How to count rows in a column whos 1st 6 character contain

Suser

New Member
Joined
Mar 30, 2017
Messages
8
Hi,

How do you count rows in a column that contain 2205, 3959 or 3858 only if the first 4 digits are one of this three numbers?

The column contains either 13 or 15 character numbers. But, each number is preceded by =" and ends with ".

Two example cells: A2 and A3

="3959506134974"
="2205253647730"

I tried
=IF(LEFT($A:$A,4) = "2205", COUNTIF($A:$A,"*2205*"))
=IF(LEFT($A:$A,4) = "3959", COUNTIF($A:$A,"*3959*"))
=IF(LEFT($A:$A,4) = "3858", COUNTIF($A:$A,"*3858*"))

but it seems to work for 2205 but not for the other two numbers, I am not sue why.

I also tried
=IF(LEFT($A:$A,4) = "3959", COUNTIF($A:$A,"*3959*"))
but it returned FALSE.

Any help. Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Thank you, Joe! The formula works! I modified a bit so that I get the count in separate cells.

2205s3959s3858s
=SUMPRODUCT(--(LEFT($A2:$A16,4)+0={2205}))=SUMPRODUCT(--(LEFT($A2:$A16,4)+0={3959}))=SUMPRODUCT(--(LEFT($A2:$A16,4)+0={3858}))
<colgroup><col width="334" style="width: 251pt; mso-width-source: userset; mso-width-alt: 5350;" span="2"> <col width="376" style="width: 282pt; mso-width-source: userset; mso-width-alt: 6016;"> <tbody> </tbody>

Is there a way to make the formulas count any number of row and not just $A2:$A11? I tried (LEFT($A:$A,4) but I got #VALUE! error. A1 is a heading.

I appreciate the help, thanks!
 
Upvote 0
Thank you, Joe! The formula works!


<tbody>
</tbody>

Is there a way to make the formulas count any number of row and not just $A2:$A11? I tried (LEFT($A:$A,4) but I got #VALUE! error. A1 is a heading.

I appreciate the help, thanks!
You are welcome. The formula returns an error if there are any blank or non-numeric cells in the specified range. Quick way to extend the row address is to put a 0 in every blank cell you want to include. So, in the example of post #2 the data are in A2:A5. If you anticipate the data could eventually expand to say A25 then put 0's in A6:A25 and change the formula to: =SUMPRODUCT(--(LEFT(A2:A25,4)+0={2205,3959,3858}))
 
Upvote 0
Thanks again, Joe! That will work.

Someone also suggested this and repeat it for each number, which seems to work as well
=COUNTIF($A:$A,"2205*")
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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