Help with COUNTIF formula

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,
i have a row of data containing 8 digit numbers and i want to count the number of 10,20 or 30 at the 5th and 6th digit
is there an easy way to do this?

Example: data in column A

10053001
24224002
14432001
54419030
44301002
10223001
55677501

not sure what to put in for the criteria but formula from above data should output a value of 4
Code:
=COUNTIFS($A:$A,??)

i could do it by creating another formula =MID(A2,5,2) but would prefer not to as theres lots of data

any help appreciated
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
are these formatted as string? try

=SUMPRODUCT((MID(A2:A8,5,2)="10")+(MID(A2:A8,5,2)="20")+(MID(A2:A8,5,2)="30"))
 
Last edited:
Upvote 0
Try this:


Excel 2012
ABC
1100530012
2242240024
314432001
454419030
544301002
610223001
755677501
Sheet2
Cell Formulas
RangeFormula
C1=SUMPRODUCT(--(MID(A1:A7,5,2)="30"))
C2=SUMPRODUCT(--(--MID(A1:A7,5,2)={10,20,30}))


If you want a formula that checks just for "30", use the top formula. You can obviously use that 3 times and sum it, or you could use the formula in C2, if you want the sum of all 3 values.

Hope this helps..
 
Last edited:
Upvote 0
appreciate the help, all are working to calculate totals of each but i wanted COUNTIF so i can use multiple criteria

like
=COUNTIFS($A:$A,"30",$B:$B,"red")

probably not possible this way
 
Last edited:
Upvote 0
COUNTIF(S) won't work because you can't use functions on the ranges. You can possibly use wildcards in the criteria, but they don't work well with numbers. I got COUNTIFS to work by formatting the numbers as text, but that's not ideal either.

But SUMPRODUCT can use multiple conditions, like so:

=SUMPRODUCT(--(MID(A1:A7,5,2)="30"),--(B1:B7="red"))

You can't use whole column references because of performance issues, but other than that, it works fine.
 
Upvote 0
What have you got against SUMPRODUCT?;)
You CAN include multiple conditions with SUMPRODUCT. It is what we used before COUNTIFS existed.
 
Upvote 0
Thanks, i didnt know sumproduct allowed multiple criteria :)

I only have at a maximum - 1000 rows so im hoping it doesn't slow things down.
 
Upvote 0
1000 rows shouldn't cause too much of a hit. But if you used full columns, that would be over 1 million rows, and that would be noticeable.
 
Upvote 0
Why does this work:
Code:
=SUMPRODUCT(--(A2:A1000=B5),--(MID(F2:F1000,5,2)="10"))

but this doesnt? just outputs #VALUE
Code:
=SUMPRODUCT(--(A2:A1000=B5),--(MID(F2:F1000,5,2)={"10","20","30"}))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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