Using INDIRECT and COUNTA

DJWH

New Member
Joined
May 9, 2008
Messages
43
Hi,

I have the following formula

=COUNTA('4-6'!A:A)-1

where the worksheet name is '4-6'

However I want to use the INDIRECT function as I need to repeat this for multiple sheets and they all have different names based on a date. The date is in cell B2... and I thought the following would work:

=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A)-1"))

However this brings the wrong value.

I have also tried:

=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A)")-1)

This doesn't give the correct answer either.

Any idea of where I am going wrong?

Thanks
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Phox

Well-known Member
Joined
Jul 26, 2004
Messages
522
The minus 1 should be outside.
Code:
=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A"))-1
 

Firefly2012

Well-known Member
Joined
Dec 28, 2011
Messages
3,638
Hi

I think it might be easiest to write that like:

=COUNTA(INDIRECT("'" & TEXT(B2,"d-m") & "'!A:A"))-1
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,201
Hi,

I have the following formula

=COUNTA('4-6'!A:A)-1

where the worksheet name is '4-6'

However I want to use the INDIRECT function as I need to repeat this for multiple sheets and they all have different names based on a date. The date is in cell B2... and I thought the following would work:

=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A)-1"))

However this brings the wrong value.

I have also tried:

=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A)")-1)

This doesn't give the correct answer either.

Any idea of where I am going wrong?

Thanks

Try...

=COUNTA(INDIRECT("'"&TEXT(B2,"d-m")&"!A:A"))-1
 

DJWH

New Member
Joined
May 9, 2008
Messages
43

ADVERTISEMENT

Try...

=COUNTA(INDIRECT("'"&TEXT(B2,"d-m")&"!A:A"))-1

Thanks for your quick response however that doesn't bring the correct result either. I can get it to work by putting the COUNTA in the '4-6' sheet and just doing a direct reference using the INDIRECT function but that is more work.
 

DJWH

New Member
Joined
May 9, 2008
Messages
43

ADVERTISEMENT

Did you try this formula? There was a typo in Aladin's

=COUNTA(INDIRECT("'" & TEXT(B2,"d-m") & "'!A:A"))-1 works now! Thanks :)

Out of interest, where was I going wrong with my attempt?
 

DJWH

New Member
Joined
May 9, 2008
Messages
43
=COUNTA(INDIRECT("'" & TEXT(B2,"d-m") & "'!A:A"))-1 works now! Thanks :)

Out of interest, where was I going wrong with my attempt?

Just realised the above reply... so it was due to having the -1 outside the box? Thanks everyone!
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,201
=COUNTA(INDIRECT("'" & TEXT(B2,"d-m") & "'!A:A"))-1 works now! Thanks :)

Out of interest, where was I going wrong with my attempt?

Typo's also...

=COUNTA(INDIRECT("'"&DAY(B2)&"-"&MONTH(B2)&"'!A:A"))-1

should also work.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,482
Messages
5,596,402
Members
414,063
Latest member
N_Bates

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
Top