Using a Variable as path and filename for lookup formula with VBA

JAlbers

Board Regular
Joined
Sep 9, 2011
Messages
60
Greetings all

I am working on a project that pulls information from several sources and builds a report for the powers that be every week. I actually have it basically working using a pivot table elsewhere but I am not getting all of the records there for some reason and I also wanted to clean up the code a bit and make it more uniform.

The problem I am having is when the code gets to this formula, instead of doing the index(match()) as intended, it is showing the file open box.

Here is the code I have been using

Code:
Range("R6:R" & LastRow).Formula = _
        "=IFERROR(INDEX('P:\Product Data\Product Data v1.00.xls'!Inventory_Type,Match($E6" & _
       ",'P:\Product Data\Product Data v1.00.xls'!Item_No,0)),"""")"
Here is the code that doesn't seem to want to work:

Code:
Dim wsData As String

wsData = "P:\Product Data\Product Data v1.00.xls"
    
Cells(6, 18).Resize(lastrow - 5, 1).FormulaR1C1 = _
        "=IFERROR(INDEX(" & wsData & "!Inventory_Type," _
            & "MATCH(R[0]C[-13]," & wsData & "!Item_No,0)),"""")"

I have just recently started using the R1C1 method instead of entering the formula and copying down, but this problem seems to be associated with the variable since it never gets to the action of actually entering the formula.

I would appreciate any help or suggestions!

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You get the file open box because Excel is not recognizing the file path/name you have entered.

The format should be:
'FilePath\[Filename.xls]SheetName'!Range

for example:
='x:\database\xyz\[lxx.xlsm]Sheet1'!A1
 
Upvote 0
For a different approach, since you're using Pivot Tables, have you considered PowerPivot? It's great at pulling data from external sources.
 
Upvote 0

Forum statistics

Threads
1,215,371
Messages
6,124,529
Members
449,169
Latest member
mm424

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