
Excel character count — Complete Guide to Counting Characters
Excel character count is basically handled with the LEN function. In practice, you may also need to exclude spaces, remove line breaks, count specific characters or words, total an entire range, and count bytes with LENB.
Quick Fix
=LEN(A2)
=LEN(SUBSTITUTE(A2," ",""))
=LEN(TRIM(CLEAN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,CHAR(160)," "),CHAR(10)," "),CHAR(13)," "))))
=LEN(A2)-LEN(SUBSTITUTE(A2,"a",""))
=IF(TRIM(A2)="",0, LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1)
=SUMPRODUCT(LEN(A2:A100))
LEN vs LENB
LEN returns the number of characters, while LENB returns the number of bytes (in DBCS environments). If you need byte calculations, verify the behavior in your environment.
Practical Examples
Handling Spaces and Line Breaks
=LEN(TRIM(CLEAN(SUBSTITUTE(SUBSTITUTE(A4,CHAR(10)," "),CHAR(13)," "))))
Count Specific Characters or Words
=LEN(A2)-LEN(SUBSTITUTE(A2,"o",""))
=LEN(LOWER(A2))-LEN(SUBSTITUTE(LOWER(A2),"a",""))
=(LEN(A5)-LEN(SUBSTITUTE(A5,"Apple","")))/LEN("Apple")
Total Length Across a Range
=SUMPRODUCT(LEN(A2:A100))
Length by Row or Column
=BYROW(A2:D10, LAMBDA(r, SUM(LEN(r))))
=BYCOL(A2:D10, LAMBDA(c, SUM(LEN(c))))
Byte Count (LENB)
=LENB(A5)
Checklist
- Exclude spaces:
SUBSTITUTE(," ","")orTRIM - Remove line breaks/tabs: Handle
CHAR(10/13/9) - Specific characters/words:
LEN - LEN(SUBSTITUTE()) - Range total:
SUMPRODUCT(LEN(range)) - Bytes:
LENB(verify in your environment)
Troubleshooting
| Symptom | Cause | Solution |
|---|---|---|
| Length is too high | Includes NBSP/line breaks | TRIM+CLEAN+SUBSTITUTE(CHAR(160)) |
| Incorrect word count | Multiple spaces/tabs | Clean up with TRIM and CLEAN |
| Specific character count is 0 | Case mismatch | Normalize with LOWER/UPPER |
| Different LENB values | DBCS/platform differences | Test samples in the target environment |
Related Articles
- Remove Hidden Spaces with TRIM and CLEAN
- TEXTSPLIT Guide
- Understanding Dynamic Arrays and SPILL
- Merge and Clean Columns in Power Query
- Complete TEXTJOIN Guide
Official documentation (recommended): Microsoft: LEN · Microsoft: LENB