Spreadsheet Practice

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 to C6
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

  1. B2"chair, desk, lamp"

    The value in B2.

  2. TRIM(B2)"chair, desk, lamp"

    TRIM: Removes extra spaces, leaving single spaces between words.

    • textB2"chair, desk, lamp"
  3. TRIM(B2)=""FALSE

    The = operator tests whether the two sides are equal.

  4. LEN(B2)17

    LEN: Number of characters.

    • textB2"chair, desk, lamp"
  5. SUBSTITUTE(B2,",","")"chair desk lamp"

    SUBSTITUTE: Replaces matching text.

    • textB2"chair, desk, lamp"
    • old_text","
    • new_text""
  6. LEN(SUBSTITUTE(B2,",",""))15

    LEN: Number of characters.

    • textSUBSTITUTE(B2,",","")"chair desk lamp"
  7. LEN(B2)-LEN(SUBSTITUTE(B2,",",""))2

    The - operator subtracts.

  8. LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+13

    The + operator adds.

  9. IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1)3

    IF: Returns one value if a test is true, another if false.

    • logical_testTRIM(B2)=""FALSE
    • value_if_true0not used
    • value_if_falseLEN(B2)-LEN(SUBSTITUTE(B2,",",""))+13

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.

FormulaResultWhen 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

In 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.