Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default Number of space in a string

Hi,

I'm trying to find a way to count the number of space in a given
string. Is there any function that can do that?

Thanks for your help,

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 698
Default Number of space in a string

Hi Kathy,

Try this.

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

If you want to know the number of WORDS in the string:

=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1

HTH
Regards,
Howard

wrote in message
ps.com...
Hi,

I'm trying to find a way to count the number of space in a given
string. Is there any function that can do that?

Thanks for your help,



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Number of space in a string

=(len(a1)-len(substitute(a1," ","")))/len(" ")

Since you're only counting a single character, you could eliminate the
denominator:

=len(a1)-len(substitute(a1," ",""))

wrote:

Hi,

I'm trying to find a way to count the number of space in a given
string. Is there any function that can do that?

Thanks for your help,


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,688
Default Number of space in a string

If you want to know the number of WORDS in the string:
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1


<space<spacetry<space<spacethis<space<space

Safer to trim first:

=LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1

Biff

"L. Howard Kittle" wrote in message
. ..
Hi Kathy,

Try this.

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

If you want to know the number of WORDS in the string:

=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1

HTH
Regards,
Howard

wrote in message
ps.com...
Hi,

I'm trying to find a way to count the number of space in a given
string. Is there any function that can do that?

Thanks for your help,





  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default Number of space in a string

I forgot to say that I'm in VBA and not in Excel.
Is the Substitute function working in VBA too cause I got an error

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Number of space in a string

If you're using xl2k or higher, VBA has Replace. If you're using xl97 or below,
you can use application.substitute.

Option Explicit
Sub testme()
Dim SpaceCtr As Long
Dim myStr As String
myStr = "asdf qwer qwer"
'myStr = Worksheets("sheet1").Range("a1").Value
SpaceCtr = Len(myStr) - Len(Replace(myStr, " ", ""))
MsgBox SpaceCtr
'or
SpaceCtr = Len(myStr) - Len(Application.Substitute(myStr, " ", ""))
MsgBox SpaceCtr
End Sub



wrote:

I forgot to say that I'm in VBA and not in Excel.
Is the Substitute function working in VBA too cause I got an error

Thanks


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Displays the number in text. (One thousand two hundred thirty four Ashish Patel Excel Worksheet Functions 1 March 20th 06 09:27 PM
help with excel number string caloy Excel Discussion (Misc queries) 3 February 28th 06 01:51 PM
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
last number array from string Michael Excel Worksheet Functions 17 August 1st 05 07:30 PM


All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"