Countif

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a column of data and I want to find how many semicolons are in that column.

So for example:

Rich (BB code):
a;
b;
c
d;

I would expect to return 3.

However, for:

Rich (BB code):
e;f;
g;
h;i;j;
k;

I expect to return 7.

I tried using:

Rich (BB code):
=COUNTIF(A:A,";"))

but it only returned 4 for my second example.

Can someone please point me in the right direction?

Thanks


EDIT SORTED:

I found the answer:

Rich (BB code):
=SUM((LEN(A:A)-LEN(SUBSTITUTE(A:A,";","")))/LEN(";"))



but can someone please explain what the formula is doing.

Thanks again.


 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Your Countif returns 0 for me with the 2nd set of data.
Try
=SUMPRODUCT(--(LEN(A1:A4)))-SUMPRODUCT(--(LEN(SUBSTITUTE(A1:A4,";",""))))
 
Upvote 0
Hi there. Try this:

Code:
<code>=SUMPRODUCT(LEN(A:A)-LEN(SUBSTITUTE(A:A, ";","")))</code>
 
Upvote 0
Thanks to both.

I forgot to mention with my formula, I entered it as an array, ie Ctrl+Shift+Enter.

But I prefer using SUMPRODUCT, :)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
but can someone please explain what the formula is doing.

For each row, it calculates the length of the cell contents minus the length after replacing all semicolons with nothing, which will give you the number of removed characters. The division part is unnecessary here, but would be required if you were looking for more than one character.
 
Upvote 0
For each row, it calculates the length of the cell contents minus the length after replacing all semicolons with nothing, which will give you the number of removed characters. The division part is unnecessary here, but would be required if you were looking for more than one character.

Thanks for the explanation.
 
Upvote 0
Thanks to both.

I forgot to mention with my formula, I entered it as an array, ie Ctrl+Shift+Enter.

But I prefer using SUMPRODUCT, :)

For your info ... SUMPRODUCT is an Array Formula ... without the need for CSE ...
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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