Excel countif to use variable as workbook name

ilovepurple

Board Regular
Joined
Mar 21, 2012
Messages
77
Hi all

I'm a newcomer to this forum so please forgive any non-compliance to any conventions etc.

My questions refers to the following (sample) data

Column A Column B Column C
Workbook Name Criteria Countif(how it should look for correct results)
'abc.xls'!$C:$C 87up =COUNTIF('abc.xls'!$C:$C, 87up)
'abc.xls'!$C:$C 88up =COUNTIF('abc.xls'!$C:$C, 88up)
'def.xls'!$C:$C 87up =COUNTIF('def.xls'!$C:$C, 87up)
'def.xls'!$C:$C 88up =COUNTIF('def.xls'!$C:$C, 88up)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Sorry, the data was badly formatted. I'll try to give it better here:

Column A             Column B             Column C
Workbook Name    Criteria    Countif(how it should look for correct results)
'abc.xls'!$C:$C       87up      =COUNTIF('abc.xls'!$C:$C, 87up)
'abc.xls'!$C:$C       88up      =COUNTIF('abc.xls'!$C:$C, 88up)
'def.xls'!$C:$C       87up      =COUNTIF('def.xls'!$C:$C, 87up)
'def.xls'!$C:$C       88up      =COUNTIF('def.xls'!$C:$C, 88up)
 
Upvote 0
Hi all

I'm a newcomer to this forum so please forgive any non-compliance to any conventions etc.

My questions refers to the following (sample) data

Column A Column B Column C
Workbook Name Criteria Countif(how it should look for correct results)
'abc.xls'!$C:$C 87up =COUNTIF('abc.xls'!$C:$C, 87up)
'abc.xls'!$C:$C 88up =COUNTIF('abc.xls'!$C:$C, 88up)
'def.xls'!$C:$C 87up =COUNTIF('def.xls'!$C:$C, 87up)
'def.xls'!$C:$C 88up =COUNTIF('def.xls'!$C:$C, 88up)
If you're wanting to "build" a formula by referring to cells that contain strings for the arguments then the source file(s) MUST be open for the formula to work properly. This is usually not desirable.
 
Upvote 0
Hi T. Valko

Thanks for your reply.

My source files are open but =COUNTIF(A1, B1) doesn't work.

I even tried =COUNTIF(CELL("contents",A1), B1) but that didn't help either :(
 
Upvote 0
Hi T. Valko

Thanks for your reply.

My source files are open but =COUNTIF(A1, B1) doesn't work.

I even tried =COUNTIF(CELL("contents",A1), B1) but that didn't help either :(
'abc.xls'!$C:$C
I assume abc.xls is the file name but what is the sheet name?

The syntax to refer to a file that is already open is:

[abc.xls]Sheet1!A1

Or, if the file name contains spaces or numbers:

'[abc 1.xls]Sheet1'!A1

So, if you want to put the components of the path in cells I would do it like this:

A2 = abc.xls
B2 = sheet1
C2 = C:C
D2 = criteria = 87up

Then the formula would be:

=COUNTIF(INDIRECT("'["&A2&"]"&B2&"'!"&C2),D2)
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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