VBA VLOOKUP to external workbook... help

Chrisjd2

Board Regular
Joined
Mar 1, 2016
Messages
61
Hi Gents,

Could you help me, I need to write VBA code to do a vlookup in a cells to an external spreadsheet that is on my desktop. I dont know where to start with the code?

It needs to be in the macro as it needs to loop through 10,000 lines.

Cheers
Chris
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If you record yourself creating the vlookup with the macro recorder it should be fine, set a range for the lookup though that accounts for the external sheets list getting bigger a some point in the unknown future, plan ahead!

Then stick it into the loop.
 
Upvote 0
If you record yourself creating the vlookup with the macro recorder it should be fine, set a range for the lookup though that accounts for the external sheets list getting bigger a some point in the unknown future, plan ahead!

Then stick it into the loop.

I've tried that, unfortunately the recorder puts the result of the worksheet function "=Vlookup... ETC" in each sell as a string. So it is not actually putting the result of the vlookup in.
 
Upvote 0
The cell your putting it in might be set to TEXT, in which case it won't accept any formula, change the format of all cells you want the lookup in to GENERAL

Code:
Range("A1").Select   

 Selection.NumberFormat = "General"
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(wahtever your reference)"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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