Conditional counting

mikemathis

Board Regular
Joined
Jul 9, 2003
Messages
135
Office Version
  1. 2019
Platform
  1. Windows
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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.
 
Upvote 0
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),"")
 
Upvote 0
I think the #VALUE error comes from empty cells in the range. You could simply use,

=SUMPRODUCT(--(LEFT(A1:A400,4)="2006"))
 
Upvote 0
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.
 
Upvote 0
Brian,

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

Thanks. That does it exactly. I'm definitely going to have to get on top of SUMPRODUCT. Works for referenced cell! woohoo!
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,428
Members
448,896
Latest member
MadMarty

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