## Count comma separated values in a cell

In this tutorial, you will learn how to use a combination of the LEN, TRIM and SUBSTITUTE functions to count comma separated values in a cell in Excel.

#### How to count comma separated values in a cell in Excel?

As the below screenshot shown, there is a comma-separated string list in column B which you want to count the comma separated values in each cell, please do as follows to achieve it.

Generic formula

=IF(ISBLANK(B3),"",LEN(TRIM(B3))-LEN(SUBSTITUTE(TRIM(B3),",",""))+1)

Arguments

A1: Represents the cell containing the comma-separated string which you will count the comma separated values.

How to use this formula?

1. Select a blank cell to output the result. In this case, I select cell D3.

2. Enter the below formula into it and press the Enter key. And then drag its Fill Handle all the way down to apply it to other cells.

=IF(ISBLANK(B3),"",LEN(TRIM(B3))-LEN(SUBSTITUTE(TRIM(B3),",",""))+1)

Note: In this formula, B3 is the cell containing the comma-separated string you will count comma separated values inside. You can change it as you need.

How does this formula work?

=IF(ISBLANK(B3),"",LEN(TRIM(B3))-LEN(SUBSTITUTE(TRIM(B3),",",""))+1)

1. LEN(TRIM(B3)): The TRIM function removes all extract spaces from the comma-separated string "AA, BB, CC, DD", and only keeps single space between words. And then the LEN function calculates the total length of "AA, BB, CC, DD" and returns the result as 14;

2. LEN(SUBSTITUTE(TRIM(B3),",",""))

• SUBSTITUTE(TRIM(B3),",",""): As the above explanation shown, the TRIM function here removes all extract space from "AA, BB, CC, DD" and returns the result as "AA, BB, CC, DD". And then the SUBSTITUTE function replaces all commas in "AA, BB, CC, DD" with nothing and get the result "AA BB CC DD";
• LEN("AA BB CC DD"): The LEN function returns the number of characters in a text string "AA BB CC DD". The result is 11.

3. 14-11+1: Here use the total length of "AA, BB, CC, DD" subtracting the total length of "AA BB CC DD" to get the total number of commas in the string (14-11=3). As there always be a word after the last comma, you need to add 1 to number 3 to get the total comma separated words in the string. Here the result is 4.

4. IF(ISBLANK(B3),"",14): The If function here says if B3 is empty, then return nothing, otherwise return the number 14. Here B3 contains values, so the IF function returns the number 14.

#### Related functions

Excel LEN function
The Excel LEN function returns the number of characters in a text string.

Excel SUBSTITUTE function
The Excel SUBSTITUTE function replaces text or characters within a text string with another text or characters.

Excel TRIM function
The Excel TRIM function removes all extra spaces from text string and only keeps single spaces between words.

#### Related formulas

Count occurrences of specific characters in an Excel cell
This tutorial introduces how to apply formulas based on the LEN and SUSTITUTE functions to count the number of times a specific character appears in an Excel cell.

Count specific characters in a range of cells
This tutorial introduces some formulas to count the number of times a specific character appears in a range in Excel.

Count specific words in a cell in Excel

Count specific words in a range in Excel
This article explains a formula to count the number of times a specific word appears in a range of cells in Excel.

Count number of characters in a cell in Excel
The total characters not only includes all letters, but also all spaces, punctuation marks and symbols in the cell. Follow this tutorial to easily count the total characters in a cell with the LEN function in Excel.

Count number of characters in a range in Excel
This article explains a formula to count total characters that appear in a range of cells in Excel.

### The Best Office Productivity Tools

#### Kutools for Excel - Helps You To Stand Out From Crowd

 🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions… Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ... Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup... Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List... Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Columns to Select Same & Different Cells ... Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ... Top 15 Toolsets:  12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

#### Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

• One second to switch between dozens of open documents!
• Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
• Increases your productivity by 50% when viewing and editing multiple documents.
• Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thanks for this formula. I had been trying a different formula: =LEN(A1)-LEN(SUBSTITUTE(A1),",",""))+1 but if the cell was blank it would have a 1 in it. This doesn't, so it works for counting up numbers. In my case, I'm trying to count the number of dates such as Oct. 6, 13, 20, 27. However, it's not working when it comes to multiplying the count by the cost of the lesson. For instance, if John had lessons on Oct. 6, 13, 20, 27, I have a column for dates of lessons, then a column for number of lessons, a column for the cost of each lesson (30 or 45), and a column to calculate monthly tuition due (number of lessons x cost). For the student with blank dates/no lessons, it gives an error value, and therefore affects my total tuition for the month. Please advise. Thanks!
This comment was minimized by the moderator on the site
Hi sir, formula is not working properly. I have numerical data in cells. It works correctly in cells where numbers consists upon two digits like 22,43,59 etc, but it fails when there comes data like 103,144 or 165,45 etc. Please help
This comment was minimized by the moderator on the site
Hi,
The formula works fine for me and do not reproduce the error you mentioned. May I ask what version of Excel you are using?
This comment was minimized by the moderator on the site
Office 2021
This comment was minimized by the moderator on the site
thanks! this worked very well, except for that it also returns "1" when the cell is blank. I'm trying to count the number of concatenated dates. There are some cells that don't have any dates, and those are coming back with the number '1'. However, the formula is still counting correctly the number of dates otherwise.
This comment was minimized by the moderator on the site
Hi Alicia Majcher,
Thank you for your feedback. If you want to return nothing when the reference cell is blank, apply the following formula.
=IF(ISBLANK(A30),"",LEN(TRIM(A30))-LEN(SUBSTITUTE(TRIM(A30),",",""))+1)
There are no comments posted here yet