Alright, this question sounds simple at first, but nothing I've tried all day will do what I want it to.
I've attached my sample workbook with my macro so you can see my data
My workbook has two sheets. sheet1 and sheet2.
My macro needs to compare column A from sheet2 with column A in sheet1. Anytime there is a match I want to take the row that matched on sheet2 and paste it on the end of the corresponding row in sheet1.
I believe I have the nested for loops that are doing the comparison working properly, what I can't figure out is how to copy the row from sheet2 and paste it at the end of the corresponding row in sheet1. It needs to be dynamic, the row lengths may differ and ideally I would like to exclude the cell in column A, sheet2 when I paste that row into sheet1, however this isn't required.
Any help is appreciated.
Here is the macro, it is also included in the attachment.
Sub merge()
Dim wellB, wellA, wellC, x, y, z As Range
Dim i, j As Integer
Dim sheet1, sheet2, Combined As Worksheet
'Create a new sheet to show the combined data
'Set Combined = ThisWorkbook.Sheets.Add
'Combined.Name = "Combined"
i = 0
Set sheet1 = ThisWorkbook.Sheets("sheet1")
Set sheet2 = ThisWorkbook.Sheets("sheet2")
Set wellA = sheet1.Range("A1").Resize(10, 1)
Set wellB = sheet2.Range("A1").Resize(10, 1)
For Each x In wellA
For Each y In wellB
If y = x Then
'I can't get anything to work properly in this area
End If
Next y
Next x
End Sub
Bookmarks