Using a Variable for filename in ActiveCell.FormulaR1C1 =

Duchesssix

New Member
Joined
Jan 6, 2011
Messages
42
I have the following formula that I want to replace va05.XLS with a variable but am not sure of the correct syntax.

ActiveCell.FormulaR1C1 = _
' "=IFERROR(VLOOKUP(RC[-3],va05.XLS!C2:C7,6,FALSE), """")"
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try

Code:
Dim MyVariable As String
MyVariable = "va05.XLS"
 
ActiveCell.FormulaR1C1 = _
' "=IFERROR(VLOOKUP(RC[-3]," & MyVariable & "!C2:C7,6,FALSE), """")"
 
Upvote 0
Thought it worked but it doesn't. i get a Run-time error '1004': Application-defined or object-defined error
 
Last edited:
Upvote 0
I know this is quite old but in responding to your recent 'About This Board' thread, I came across this thread and do have some input.

As a matter of interest, is the va05.XLS in your formula another worksheet name in the active workbook, or another workbook where you might be looking in the first, or only, worksheet?

Apart from the apostrophe on the second line of your code (and jonmo1's), which I presume you have removed, try this which should cope better if the variable contains any spaces.
Rich (BB code):
Dim MyVariable As String

MyVariable = "abc def.xls"
 
ActiveCell.FormulaR1C1 = _
    "=IFERROR(VLOOKUP(RC[-3],'" & MyVariable & "'!C2:C7,6,FALSE), """")"
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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