Hi, I'm new to the board and a newbie to VBA. I tried different approaches found online but seems none of mine works.
So here is my questions: I need to copy 5 columns from Worksheet A to Worksheet B. The columns in worksheet A and B have different rows: let's assume wsA has 20 rows and wsB has 10 rows but they are not fixed. The only identical column in both sheets are their IDs so we may need to use IDs to match first, then do the copy.
I tried:
1. wsA.Range("B2:F").Copy destination wsB.Range("C2:G")
wsA.Range("B2:F").Copy
2. wsB.Range("C2:G").PasteSpecials
3. wsA.Range(wsA.Cells(1, "B"), wsA.Cells(wsA.Rows.Count, "F").End(xlUp)).Copy
wsB.range(“E1”).Insert xlShiftDown
4. For i=1 to lastrowA
For j=1 to lastrow B
If wsA.Cells(IDs).Value = wsB.Cells(IDs).Value Then
wsA.Cells(i,2).Value = wsB.Cells(j,3).Values
Can someone help
Thank you!
So here is my questions: I need to copy 5 columns from Worksheet A to Worksheet B. The columns in worksheet A and B have different rows: let's assume wsA has 20 rows and wsB has 10 rows but they are not fixed. The only identical column in both sheets are their IDs so we may need to use IDs to match first, then do the copy.
I tried:
1. wsA.Range("B2:F").Copy destination wsB.Range("C2:G")
wsA.Range("B2:F").Copy
2. wsB.Range("C2:G").PasteSpecials
3. wsA.Range(wsA.Cells(1, "B"), wsA.Cells(wsA.Rows.Count, "F").End(xlUp)).Copy
wsB.range(“E1”).Insert xlShiftDown
4. For i=1 to lastrowA
For j=1 to lastrow B
If wsA.Cells(IDs).Value = wsB.Cells(IDs).Value Then
wsA.Cells(i,2).Value = wsB.Cells(j,3).Values
Can someone help
Thank you!