title: excel vba macro to match cells from two different workbooks and copy and paste accordingly
body: <p>i have 2 workbooks, workbook A and workbook B. Each workbook has a table.  workbook A has 2 columns. All three columns are filled.</p>
  
  <ol>
  <li>product_id</li>
  <li>Machine_number and </li>
  </ol>
  
  <p>Workbook B has the same 2 columns but only one column, Product_id, is filled. The other 1 column is vacant. </p>
  
  <p>I need to match the cells of product_id of both workbooks. If the product_id found in workbook A matches workbook B, then the machine number of that product id should be copied from workbook A to workbook B.</p>
  
  <p>I have performed this using this code:</p>
  
  <pre><code>Sub UpdateW2()
  
  Dim w1 As Worksheet, w2 As Worksheet
  Dim c As Range, FR As Long
  
  Application.ScreenUpdating = False
  
  Set w1 = Workbooks("workbookA.xlsm").Worksheets("Sheet1")
  Set w2 = Workbooks("workbookB.xlsm").Worksheets("Sheet1")
  
  
  For Each c In w1.Range("A2", w1.Range("A" &amp; Rows.Count).End(xlUp))
    FR = 0
    On Error Resume Next
    FR = Application.Match(c, w2.Columns("A"), 0)
    On Error GoTo 0
    If FR &lt;&gt; 0 Then w2.Range("C" &amp; FR).Value = c.Offset(, 0)
  Next c
  Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>There is a cell that says "machine 4" in product number column. This cell does not get copied and pasted alongside the corresponding product_id value in workbook B. </p>
  
  <p>The rest of the machine numbers for the product ids get copied and pasted accordingly.</p>
  
  <p>These are the screenshots of results
  <img src="https://i.stack.imgur.com/iLycG.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/GibuD.png" alt="enter image description here"></p>
  
  <p>The first screenshot is
  Workbook B</p>
  
  <p>The second screenshot is
  Workbook A</p>
  
  <p><strong>I have no idea why this happens, can someone please give me the reason for this?</strong></p>
  
  <p>................................................................................
  <strong>UPDATE</strong></p>
  
  <p>I found that the issue ive descriped in the question arises when the product_id(style_number) repeats.</p>
  
  <p>Say if product_id GE 55950 is present in 2 cells,in both workbooks. Then when i execute the macro only one of the cells is detected. </p>
  
  <p>I tried the coding in both answers but neither solved this problem.</p>
  
  <p>Below is a screenshot of the results.
  <img src="https://i.stack.imgur.com/e6m1X.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/HGbfp.jpg" alt="enter image description here"></p>
  
  <p><strong>In the screenshots the cell with machine 7 is not shown. Can someone tell me why this happens?</strong></p>