Spreadsheet Practice

How to count comma-separated items in a cell in Excel

Formula (Excel and Google Sheets)

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

Count the commas and add 1, returning 0 for an empty cell: =IF(TRIM(B2)="",0,LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1).

Result on the example
one result per row in C2, filled down to C8
Works in
Excel 2024 and Microsoft 365
Google Sheets
Same formula

See it work

The formula is already in C2, filled down to C8. 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. Removing the commas with SUBSTITUTE and comparing lengths gives the number of commas, and adding 1 gives the items. The IF handles the empty order, which has no commas but also no items.

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

Result3

  1. B2"Desk, Chair, Lamp"

    The value in B2.

  2. TRIM(B2)"Desk, Chair, Lamp"

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

    • textB2"Desk, Chair, Lamp"
  3. TRIM(B2)=""FALSE

    The = operator tests whether the two sides are equal.

  4. LEN(B2)17

    LEN: Number of characters.

    • textB2"Desk, Chair, Lamp"
  5. SUBSTITUTE(B2,",","")"Desk Chair Lamp"

    SUBSTITUTE: Replaces matching text.

    • textB2"Desk, Chair, Lamp"
    • old_text","
    • new_text""
  6. LEN(SUBSTITUTE(B2,",",""))15

    LEN: Number of characters.

    • textSUBSTITUTE(B2,",","")"Desk Chair 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,",")))Excel only3, 1, 0…Excel 2024 and Microsoft 365: TEXTSPLIT splits the list into cells and COUNTA counts them.
=IF(TRIM(B2)="",0,COUNTA(SPLIT(B2,",")))Google Sheets3, 1, 0…Google Sheets: SPLIT does the same job, and it skips empty items from doubled commas.

Common mistakes

  • A trailing comma ("Desk, Chair,") counts an extra, empty item with the comma method. Clean the list, or use the Sheets SPLIT version, which ignores empty parts.
  • Without the IF, an empty cell returns 1.

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 comma-separated items in a cell

In C2, count the comma-separated items in the order, returning 0 for an empty cell, then fill down to C8.

Questions

How do I count items separated by semicolons or line breaks?

Change the separator: ";", or CHAR(10) for line breaks.

How do I count how many orders include a particular item?

Use COUNTIF with wildcards: =COUNTIF(B2:B8,"*Chair*").

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.