how to count spaces in a text string

loverfellow

Board Regular
Joined
Mar 4, 2008
Messages
116
I am looking for this for some time. Is there any formula (not vba) to count that how many occurances of spaces are in a text string, spaces could be more than one between the words.
Help me with this please.
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
There are often many ways.

It sounds like we have different definitions of a space? The formula I posted counted spaces in the text string, and yes than can be more than one between the words. Every space (character) is counted.

What is your definition?
 
Upvote 0
no, this don't count multiple spaces between words. Could there be any other formula

Did you apply this formula the way it shown here ? It is not possible the formula will not count multiple spaces in between words. It will infact all the spaces in the text string.
 
Upvote 0
Oh, you are right, it counts all the spaces. But I have a text in a worksheet, only where it didn't apply. There are obviously 9 spaces in that text but the formula counts only 4. I believe those spaces were not entered in a normal way. Anyone have any idea about this?
 
Upvote 0
What do you want to do?

Maybe apply a CLEAN function to remove them?

To investigate the characters, isolate them individually using the MID function - so put one character in one cell. And then use the CODE function to work out what the character is. You might also want to use the TRIM or LEN functions, too.
 
Upvote 0
What do you want to do?

Maybe apply a CLEAN function to remove them?

To investigate the characters, isolate them individually using the MID function - so put one character in one cell. And then use the CODE function to work out what the character is. You might also want to use the TRIM or LEN functions, too

hi Fazza,

I think he is exporting the data (text strings) into Excel which is causing this to happen and I do agree that using CLEAN() he will be able to remove junk characters which may have become a part of these strings !
 
Upvote 0
thanks guys, the problem is solved. It was some kind of junk character which code is 160 while the code of the a normal space is 32. So, this was the text "Mf Offset Paper ", and I finally used this formula which worked fine.
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+(LEN(A1)-LEN(SUBSTITUTE(A1," ","")))
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,183
Members
448,872
Latest member
lcaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top