I have two Excel worksheets: Sheet1 and Sheet2. Sheet2 is the master list while Sheet1 is the updated worksheet I receive from the system. What I need is to compare each value of Col A of Sheet1 with Sheet2. If there is a match, then I want to copy the entire matching row from Sheet1 and paste values from that row to the corresponding ColA value (Item#) row of Sheet2. Example shown below:
Sheet1 Worksheet
ColA ColB
Item# Updated Cost
1234 $30
Sheet2 Worksheet
ColA ColB
Item# Current Cost
1234 $45
There are more columns in my file than shown here, so its necessary to copy the entire row with the corresponding row in Sheet2. I started the needed Excel VBA code, but I'm stuck on the part to paste corresponding values in Sheet2. My code is pretty basic and it isn't working yet, so any help related to coding is appreciated.
Sub Macro1()
'
' Macro1 Macro
'
' Copies corresponding item# rows from sheet1 worksheet
' to sheet2 worksheet by comparing item# column
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ColA As String
Dim rng1 As Range
Dim rng2 As Range
Dim RowCounter1 As Integer
Dim RowCounter2 As Integer
ColA = "A"
RowCounter1 = 2
RowCounter2 = 2
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Do While Not IsEmpty(ws1.Range(ColA & RowCounter1).Value)
Set rng1 = ws1.Range(ColA & RowCounter1)
RowCounter2 = 1
Do While Not IsEmpty(ws2.Range(ColA & RowCounter2).Value)
Set rng2 = ws2.Range(ColA & RowCounter2)
If rng1.Value = rng2.Value Then
Rows(RowCounter1).EntireRow.Copy
RowCounter2 = RowCounter2 - 1
End If
RowCounter2 = RowCounter2 + 1
Loop
RowCounter1 = RowCounter1 + 1
Loop
End Sub