title: Compare values in two different workbooks sheets and paste value of 1st workbook into 2nd workbook
body: <p>Want to Compare the value incrementally from sheet1 of workbook1 with value of sheet1 of workbook2 and copy paste data of sheet 1 to sheet 2 if values match, WB1S1 contains three columns two value to compare and thirs to copy, WB2S1 contains two columns both to compare with WB1S1 first two columns if value match copy WB1S1 third column values to WB2S1, , the value can be any way, e.g  A1:B1 of WB1S1 matches A2:B2 of WB2S1 then, C1 of WB1S1 to be copied to C2 of WB2S1</p>
  <p>Here is the code</p>
  <pre><code>Sub Compare()
  
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  
  Dim myTemp As Workbook, myMain As Workbook
  Dim temppath As String, mainfile As String
  Dim wsTempwsMain As Worksheet, wsMain As Worksheet
  
  temppath = &quot;workbook1.xlsx&quot;
  mainfile = &quot;workbook2.xlsx&quot;
  
  Set myTemp = Workbooks.Open(filename:=temppath)
  Set wsTemp = myTemp.Sheets(&quot;Sheet1&quot;)
  
  Set myMain = Workbooks.Open(filename:=mainfile)
  Set wsMain = myMain.Sheets(&quot;Sheet1&quot;)
  
  wsTemp.Activate
  wsMain.Activate
  
  Dim TemplastRow As Long, MainlastRow As Long
  Dim MainLastColumn As Long
  
  
  TemplastRow = wsTemp.Range(&quot;B2&quot;).End(xlDown).Row
  
  MainlastRow = wsMain.Range(&quot;B4&quot;).End(xlDown).Row
  
  With wsMain.UsedRange
      MainLastColumn = .Columns(.Columns.Count).Column
  End With
   
  For i = 2 To TemplastRow
      For j = 4 To MainlastRow
              
          If myTemp.wsTemp.Range(Cells(i, 2), Cells(i, 2)).Value = myMain.wsMain.Range(Cells(j, 2), Cells(j, 2)).Value And myTemp.wsTemp.Range(Cells(i, 3), Cells(i, 3)).Value = myMain.wsMain.Range(Cells(j, 3), Cells(j, 3)).Value Then
              myTemp.wsTemp.Range(Cells(i, 4), Cells(i, 8)).Select
              Selection.Copy
              myMain.wsMain.Range(Cells(j, MainLastColumn), Cells(j, MainLastColumn)).Select
              wsMain.Paste
          End If
      Next j
  Next i
  
   myWb.Save
  myWb.Close SaveChanges:=True
  
  End Sub
  </code></pre>