Count comma separated items in a string

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good morning,

I have just spent hours poring over some data where I could have saved myself a lot of trouble with a simple formula.

I have a range of cells containing labels such as "Live, Pre-Production", "UAT, Pre-Production, Live", "Live, Inactives, UAT, Development" etc.

I needed to count the number of items in each cell, assuming that they were separated by commas. So, the formula would need to return the value 2 for the first of my examples, 3 for the second and 4 for the third.

It needs to use the logic "If the cell is blank, return 0, if the cell is not blank, but does not contain a comma, return 1, otherwise, return (number of commas +1) i.e. if there are two commas in the string, then there must be three items, and so on.

I understand the logic of what I'm trying to do, I'm just stuck on the bit that counts the number of commas found in the string - can anyone help?

As always, all advice gratefully received! :-)

Pete
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
=COUNTIF($E$13:$E$16,"*"&H13&"*")

1) Identify your unique values in a column
2) In the adjacent cell, enter the formula =COUNTIF($E$13:$E$16,"*"&H13&"*") where E13:E16 is the range you want to search and H13 is the value you want to find. By inserting H13 between two *, you'll be performing a wildcard search.

Good luck!

This is AWESOME! Thanks, Clyde!!!

Although this will be very useful, it requires that values be pre-defined (controlled) and laid down into columns or rows for proper categorization of counts. I was thinking more of how this formula would apply to Pivot Table-like presentation where you would only define certain criteria then it would count the same way.
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

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