Can you concatenated a workbook name into a formula?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
I have a formula that needs to reference another worksheet selected by the user. The name of this worksheet will always be different, so I need an adaptable solution.

The good news is that by using VBA I will know what the name of the file is. I've tried writing that name to a cell in my workbook and altered the formula to concatenate the file name into it. But that throws and error.

This is my attempt at concatenating the name:

Code:
=IF(B2="","",IF(SUM(COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000]"["&G1&"]"&[/COLOR]Vortex!$L:$L,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000]"["&G1&"]"&[/COLOR]Vortex!$N:$N,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000]"["&G1&"]"&[/COLOR]Vortex!$P:$P,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000]"["&G1&"]"&[/COLOR]Vortex!$R:$R,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000]"["&G1&"]"&[/COLOR]Vortex!$T:$T,B2),COUNTIF[COLOR=#ff0000]("["&G1&"]"&[/COLOR]Vortex!$V:$V,B2))>0,"P","O"))

This is the formula that works when I manually enter the name of the other workbook:

Code:
=IF(B2="","",IF(SUM(COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$L:$L,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$N:$N,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$P:$P,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$R:$R,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$T:$T,B2),COUNTIF[COLOR=#000000]([/COLOR][COLOR=#ff0000][Feb3_Mar2.xlsx][/COLOR]Vortex!$V:$V,B2))>0,"P","O"))

How can I do this please?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I don't believe it will allow you to use a cell reference for the workbook name. I have tried seferal different methods of using a cell reference and they all produce either a Ref Or Name error. the formula parser shows that part of the statement as invalid.
 
Upvote 0
If the other workbook is open, you can try INDIRECT, something like:

...COUNTIF(INDIRECT("["&G1&"]Vortex!$L:$L"),B2)...

INDIRECT won't work on closed workbooks though.
 
Upvote 0
Hey, thanks Eric!

Unfortunately, it still didn't work for me. I think the problem is that the cell reference containing the name translates to "Feb3_Mar2", and that's with the quotation marks:


Code:
....INDIRECT("["&"Feb3_Mar2"&"]Vortex!$L:$L")....

Unless I'm overlooking something?
 
Upvote 0
you need the complete file name in G1, includihng the extension, and it will work. If you do not have quotation marks in the cell, Excel should not be putting them ohn for you. If you do have them in G1 then remove them and try the formula.

@Eric W, I didn't think about about Indirect.
 
Last edited:
Upvote 0
To get rid of the " marks, you may have to use SUBSTITUTE. And like JLGWhiz said, you'll need the extension, so something like this:

...INDIRECT("["&SUBSTITUTE(G1,"""","")&".xlsx]Vortex!$L:$L")...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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