How to count items in a comma-separated list in Excel
Formula (Excel and Google Sheets)
=IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1)Count the commas and add one: =IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1).
- Result on the example
- one result per row in
C2, filled down toC6 - Works in
- Excel 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in C2, filled down to C6. Change any input and the result updates, or edit the formula to experiment.
How it works
A list of n items has n-1 commas. LEN(B2)-LEN(SUBSTITUTE(B2,",","")) counts the commas, and adding one gives the items. The IF returns 0 for an empty cell, which would otherwise count as one item.
=IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1)Result3
B2"chair, desk, lamp"The value in B2.
TRIM(B2)"chair, desk, lamp"TRIM: Removes extra spaces, leaving single spaces between words.- text
B2"chair, desk, lamp"
- text
TRIM(B2)=""FALSEThe = operator tests whether the two sides are equal.
LEN(B2)17LEN: Number of characters.- text
B2"chair, desk, lamp"
- text
SUBSTITUTE(B2,",","")"chair desk lamp"SUBSTITUTE: Replaces matching text.- text
B2"chair, desk, lamp" - old_text
"," - new_text
""
- text
LEN(SUBSTITUTE(B2,",",""))15LEN: Number of characters.- text
SUBSTITUTE(B2,",","")"chair desk lamp"
- text
LEN(B2)-LEN(SUBSTITUTE(B2,",",""))2The - operator subtracts.
LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+13The + operator adds.
IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1)3IF: Returns one value if a test is true, another if false.- logical_test
TRIM(B2)=""FALSE - value_if_true
0not used - value_if_false
LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+13
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(TRIM(B2)="",0,COUNTA(TEXTSPLIT(B2,","))) | 3, 1, 0… | Excel 365: split the list and count the pieces. |
Common mistakes
- A trailing comma ("chair, desk,") adds an item that isn't there. In Excel 365, ignore empty pieces:
COUNTA(TEXTSPLIT(B2,",",,TRUE)). - Spaces around commas don't matter here, since only the commas are counted.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Count items in a comma-separated list
C2, count the items in the comma-separated list (0 when it's empty) and fill down to C6.Questions
How do I count the items across all orders?
Sum the column, or in one formula: =SUMPRODUCT((TRIM(B2:B6)<>"")*(LEN(B2:B6)-LEN(SUBSTITUTE(B2:B6,",",""))+1)).
How do I check whether the list contains a specific item?
Search with commas around both: =ISNUMBER(SEARCH(", desk,",", "&B2&",")).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.