Hi,
I have 80,000 records in sheet1, and 10,000 records in sheet2.
What I want to do is that I have to find the same value in column A in sheet1 with column A in sheet2.
If I find the same value in column A in sheet1, then copy value in column A and column B in sheet2, then paste it into column D and E in sheet1.
sheet1 looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]0.023[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.0115[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]20[/TD]
[TD]0.005[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]27[/TD]
[TD]0.89[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
sheet2 looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]6[/TD]
[TD]0.12[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.568[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]27[/TD]
[TD]0.047[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]33[/TD]
[TD]0.56[/TD]
[/TR]
</tbody>[/TABLE]
Expect results looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[TD][/TD]
[TD]Item from sheet2[/TD]
[TD]Rate from sheet2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]0.023[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.0115[/TD]
[TD][/TD]
[TD]8[/TD]
[TD]0.568[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]20[/TD]
[TD]0.005[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]27[/TD]
[TD]0.89[/TD]
[TD][/TD]
[TD]27[/TD]
[TD]0.047[/TD]
[/TR]
</tbody>[/TABLE]
So, I tried below vba code, but it took forever.
Please advise me how to process this faster and easier way.
Thanks in advance.
I have 80,000 records in sheet1, and 10,000 records in sheet2.
What I want to do is that I have to find the same value in column A in sheet1 with column A in sheet2.
If I find the same value in column A in sheet1, then copy value in column A and column B in sheet2, then paste it into column D and E in sheet1.
sheet1 looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]0.023[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.0115[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]20[/TD]
[TD]0.005[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]27[/TD]
[TD]0.89[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
sheet2 looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]6[/TD]
[TD]0.12[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.568[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]27[/TD]
[TD]0.047[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]33[/TD]
[TD]0.56[/TD]
[/TR]
</tbody>[/TABLE]
Expect results looks like below
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Item[/TD]
[TD]Rate[/TD]
[TD][/TD]
[TD]Item from sheet2[/TD]
[TD]Rate from sheet2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]0.023[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]8[/TD]
[TD]0.0115[/TD]
[TD][/TD]
[TD]8[/TD]
[TD]0.568[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]20[/TD]
[TD]0.005[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]27[/TD]
[TD]0.89[/TD]
[TD][/TD]
[TD]27[/TD]
[TD]0.047[/TD]
[/TR]
</tbody>[/TABLE]
So, I tried below vba code, but it took forever.
Code:
Set wsD = ThisWorkbook.Sheets("sheet1")
lrR = wsD.Cells(Rows.Count, 1).End(xlUp).Row 'col A
Set ws = ThisWorkbook.Sheets("sheet2")
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
With ws
For m = 3 To lr
With wsD.Range("A3:A" & lrR)
For n =3 To lrR
If ws.Range("A" & m) = wsD.Range("A" & n) Then
ws.Range("A" & m & ":" & "B" & m).Copy
wsD.Range("D" & n).PasteSpecial xlPasteValuesAndNumberFormats
GoTo skip
End If
Next n
End With
skip:
Next m
End With
Please advise me how to process this faster and easier way.
Thanks in advance.
Last edited: