Skip to main content

How to count the number of spaces of text string in Excel?

Author: Xiaoyang Last Modified: 2024-09-05

Have you ever tried to count the number of spaces of text string in a cell? Of course, you can count them one by one manually, but, if there are multiple cells needed to be counted, this way will be tedious and time consuming. Today, I can talk about some formulas for dealing with this problem in Excel.

Count the number of all spaces of text string with formula

Count the number of all spaces of text string with Kutools for Excel

Count the number of leading spaces of text string with formula


Count the number of all spaces of text string with formula

To get the number of all spaces among the text string, the following formula can help you, please do as this:

1. Enter this formula: =LEN(A2)-LEN(SUBSTITUTE(A2," ",""))(A2 contains the text string that you want to count the spaces) into a blank cell, see screenshot:

apply a formula to count spaces

And then drag the fill handle over to the cells which you want to apply this formula, and all the spaces of a cell have been counted as follows:

drag and fill the formula to other cells


Count the number of all spaces of text string with Kutools for Excel

If you have Kutools for Excel, its COUNTCHAR function of Kutools Functions may help you quickly count the number of times a specific character (such as a specific letter, comma, space and so on) appears within a cell.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

After installing Kutools for Excel, please do as follows:

1. Click a cell where you want to put the result, B2, for example.

2. Then click Kutools > Kutools Functions > Statistical & Math > COUNTCHAR, see screenshot:

click COUNTCHAR feature of kutools

3. In the Function Arguments dialog box, click  select button button from the Within_text to select the cell that you want to get the number of the spaces, and then type the space bar once in the Find_text box, see screenshot:

set the arguments in the dialog box

4. Then click OK button, you will get the number of spaces in the text string, and then drag the fill handle down to the cells which you want to apply this formula, all the spaces among the text strings have been counted at once. See screenshot:

get the number of spaces by kutools

Free Download Kutools for Excel Now


Count the number of leading spaces of text string with formula

The above formula can help you to count all spaces among the text string, but, if you just need to count the leading spaces of text string, I can introduce you another formula.

1. Please type this formula: =FIND(LEFT(TRIM(A2),1),A2)-1 (A2 contains the text string that you want to count the spaces) into a blank cell, see screenshot:

apply a formula to count the number of leading spaces

2. Then drag the fill handle over to the range that you want to contain this formula, and then all the leading spaces before the text string have been counted, see screenshot:

drag and fill the formula to other cells


Related articles:

How to count the number of times a character /word appears in a cell?

How to countif with multiple criteria in Excel?

How to use countif to calculate the percentage in Excel?

How to countif a specific value across multiple worksheet?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions…
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!