Count number of spaces in a string

This tutorial shows how to count the number of spaces in a string using an Excel formula, with the LEN and SUBSTITUTE functions

EXCEL FORMULA 1. Count number of spaces in a string

EXCEL

Hard coded formula
Count number of spaces in a string
Cell reference formula
Count number of spaces in a string
=LEN("Using excel")-LEN(SUBSTITUTE("Using excel"," ",""))
=LEN(B5)-LEN(SUBSTITUTE(B5," ",""))
GENERIC FORMULA

=LEN(string)-LEN(SUBSTITUTE(string," ",""))

ARGUMENTS
string: A string from which to count the number of spaces.

GENERIC FORMULA

=LEN(string)-LEN(SUBSTITUTE(string," ",""))

ARGUMENTS
string: A string from which to count the number of spaces.

EXPLANATION

This formula uses the SUBSTITUTE function to remove the spaces from a string and then applies the LEN function to count the number of character from the string without space. The LEN function is also used to calculate the number of characters from a string which includes spaces. The formula then subtracts the number of characters derived from a string that excludes spaces from number of characters derived from a string that includes spaces.

Click on either the Hard Coded or Cell Reference button to view the formula that has the string from which to count the number of spaces directly entered into the formula or referenced to a range of cells.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to count the total number of characters in a cell, excluding spaces
How to count total number of characters in a range, excluding spaces

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel SUBSTITUTE function replaces characters with another in a specified string
The Excel LEN function returns the number of characters in a specified string