I am new to macros in excel and I am trying to create one that will help me to copy data from cells from one sheet to another based on matching. Basically I want excel to look into Column H from Sheet1 and if data from any cell will match data from any cell in Column E from Sheet2, it will copy a column range from Sheet1 to Sheet2 to the relevant row (where the matching was found).
For example: If data from H5 (sheet1) matches data from E1 (sheet2) than cells I5 to J5 (sheet1) should be copied to cells F1 to G1.
Currently I have this macro which is doing part of the job:
Sub asd()
For Counter = 1 To 10
If Sheets(1).Range("H" & Counter).Value = Sheets(2).Range("E" & Counter).Value Then
Sheets(2).Range("F" & (Counter)).Value = Sheets(1).Range("I" & Counter).Value
Sheets(2).Range("G" & (Counter)).Value = Sheets(1).Range("J" & Counter).Value
End If
Next Counter
End Sub
The problem with it is that as soon as there is no match between column H (sheet1) to column E (Sheet2) the macro stops. I am sure there is a simple way to make it jump to the next row if there is no match until all rows are done.
Can anyone edit this code to make it work?
For Counter = 1 To 10
? Try stepping through your code one line at a time with the debugger (press F8 to execute each line of code), and see what's happening. – FreeMan