Vlookup referencing another workbook in vba macro

agohir

New Member
Joined
Aug 5, 2016
Messages
14
Hi,

I'm trying to reference another workbook in vlookup formula but I get an error. Is there a way I can reference another workbook without having the workbook open. I tried two formula's below (1. setting workbook as variable and 2. putting workbook directory in the vlookup itself).:

1)
Dim MasterTracker As String
MasterTracker = "U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]"

Range("AA2").Select
Active.Formula = "=IF(VLOOKUP(VLOOKUP(W2,'" & MasterTracker & "Current CDM Plan #'!$B:$C,2,FALSE)&W2&V2,'" & MasterTracker & "Database'!$BE:$BF,2,FALSE)>X2,""Flag"","""")"

2)
Active.Formula = "=IF(VLOOKUP(VLOOKUP(W2,'U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]Current CDM Plan #'!$B:$C,2,FALSE)&W2&V2,'U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]Database'!$BE:$BF,2,FALSE)>X2,""Flag"","""")"


The formula works in excel, its just when I try in vba it gives error.

Please help. Thanks!
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I think I found the error myself. The error was I wrote Active.Formula. The correction is ActiveCell.Formula :biggrin:

Hi,

I'm trying to reference another workbook in vlookup formula but I get an error. Is there a way I can reference another workbook without having the workbook open. I tried two formula's below (1. setting workbook as variable and 2. putting workbook directory in the vlookup itself).:

1)
Dim MasterTracker As String
MasterTracker = "U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]"

Range("AA2").Select
Active.Formula = "=IF(VLOOKUP(VLOOKUP(W2,'" & MasterTracker & "Current CDM Plan #'!$B:$C,2,FALSE)&W2&V2,'" & MasterTracker & "Database'!$BE:$BF,2,FALSE)>X2,""Flag"","""")"

2)
Active.Formula = "=IF(VLOOKUP(VLOOKUP(W2,'U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]Current CDM Plan #'!$B:$C,2,FALSE)&W2&V2,'U:\OPERATIONS\Working Folder\[#Master Tracker.xlsm]Database'!$BE:$BF,2,FALSE)>X2,""Flag"","""")"


The formula works in excel, its just when I try in vba it gives error.

Please help. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,060
Messages
6,169,861
Members
452,286
Latest member
noclue2000

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