VBA and VLOOKUP

A_Al

New Member
Joined
May 25, 2021
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
Hello,
Is there a VBA macro that would allow me to match the data in Sheet1 with Sheet2 as a VLOOKUP formula?
I tried the below code but it takes too long/slow:

VBA Code:
Private Sub CommandButton1_Click()
For I = 2 To 573168
Worksheets("Sheet1").Cells(I, 31).Value = Application.VLookup( _
Worksheets("Sheet1").Cells(I, 6).Value, Worksheets("Sheet2").Range("A:B"), 2, 0)
Next

I have attached an example of my request, please note that the file contains more than 500,000 rows.
 

Attachments

  • Capture.PNG
    Capture.PNG
    52.4 KB · Views: 8

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,​
yes as looping cell-by-cell is slower than applying a formula directly in all the range !​
So why don't you go to the formula way ?​
 
Upvote 0
Thanks Marc.
The formula takes too long, I want a faster way if possible
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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