Find the same value in column A in different sheet, then paste value in column B, but too long to process

borntobe

Board Regular
Joined
Dec 13, 2013
Messages
66
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.


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:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top