Conditional counting

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
120
I have a column of invoices which start with the year:

200602040005

where -
2006 is year
02 is month
05 is day
0005 is a sequential number

What I want to do is to take this list, which contains multiple years and count the number of instances where the year is 2006

I've tried to do it with CountIF and LEFT, but that's not working for me.

Any help out there?
many thanks.
Mike
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,209
=SUMPRODUCT((LEFT(A2:A400,4)+0=C2)+0)

where A2:A400 houses invoices and C2 the criterion year of 2006.
 

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
120
Aladin,

Thanks for the formula... It's not working for me though. I checked and my invoices are formatted as numbers as is the cell for 2006.

I get a #VALUE! response.
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,209
Aladin,

Thanks for the formula... It's not working for me though. I checked and my invoices are formatted as numbers as is the cell for 2006.

I get a #VALUE! response.

=IF(N(C2),SUMPRODUCT((LEFT(A2:A400&"0000",4)+0=C2)+0),"")
 

Brian from Maui

MrExcel MVP
Joined
Feb 16, 2002
Messages
8,458

ADVERTISEMENT

I think the #VALUE error comes from empty cells in the range. You could simply use,

=SUMPRODUCT(--(LEFT(A1:A400,4)="2006"))
 

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
120
I saw my problem... the range was bigger than the data - so I had some null values.

Is there a way to account for nulls? I'd like to pick a 'huge' range and then 'grow' into the formula.

Many thanks for walking me through this. I'm going to have to look up this SUMPRODUCT formula.
 

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
120

ADVERTISEMENT

Brian,

That works for an embedded year value (thanks!) but when I reference a cell with the year in it, it doesn't.
 

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
120
Aladin,

Thanks. That does it exactly. I'm definitely going to have to get on top of SUMPRODUCT. Works for referenced cell! woohoo!
 

Brian from Maui

MrExcel MVP
Joined
Feb 16, 2002
Messages
8,458
Brian,

That works for an embedded year value (thanks!) but when I reference a cell with the year in it, it doesn't.

Because the LEFT function returns text, entering 2006 in a cell and using that cell as a reference will not work, as the cell that houses 2006 is numeric.
 

Forum statistics

Threads
1,141,756
Messages
5,708,333
Members
421,566
Latest member
7Nabisco

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