Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default counting spaces in a string

1. Is there a simple way to count the spaces in a long string?
2. If you have multiple spaces in a string, is there a simple way to
determine what position in the string, number 4 space is?

Thanks
xnman

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default counting spaces in a string

1. =LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
2. =FIND(" ",A1,FIND(" ",A1,FIND(" ",A1,FIND(" ",A1)+1)+1)+1)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"xnman" wrote in message
...
1. Is there a simple way to count the spaces in a long string?
2. If you have multiple spaces in a string, is there a simple way to
determine what position in the string, number 4 space is?

Thanks
xnman



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default counting spaces in a string

"xnman" wrote...
1. Is there a simple way to count the spaces in a long string?


Simplest:

n = Len(s) - Len(Application.WorksheetFunction.Substitute(s, " ", ""))

2. If you have multiple spaces in a string, is there a simple way to
determine what position in the string, number 4 space is?


You could use something like

n = InStr(1, Application.WorksheetFunction.Substitute(s, " ", Chr(127), _
inst), Chr(127))

--
Never attach files.
Snip unnecessary quoted text.
Never multipost (though crossposting is usually OK).
Don't change subject lines because it corrupts Google newsgroup archives.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default counting spaces in a string

Bob, Thanks for your quick response. I apologize, but I was asking the
questions in reference to vba. Any suggestions on that for both questions?

Bob Phillips wrote:

1. =LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
2. =FIND(" ",A1,FIND(" ",A1,FIND(" ",A1,FIND(" ",A1)+1)+1)+1)


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default counting spaces in a string

Thanks guys! You're the best.
xnman

Harlan Grove wrote:
"xnman" wrote...

1. Is there a simple way to count the spaces in a long string?



Simplest:

n = Len(s) - Len(Application.WorksheetFunction.Substitute(s, " ", ""))


2. If you have multiple spaces in a string, is there a simple way to
determine what position in the string, number 4 space is?



You could use something like

n = InStr(1, Application.WorksheetFunction.Substitute(s, " ", Chr(127), _
inst), Chr(127))

--
Never attach files.
Snip unnecessary quoted text.
Never multipost (though crossposting is usually OK).
Don't change subject lines because it corrupts Google newsgroup archives.


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
Find String in another string - only between spaces Nir Excel Worksheet Functions 9 November 2nd 06 11:31 AM
Insert spaces in String of Numbers Marianne Excel Worksheet Functions 1 August 25th 06 06:32 PM
Removing Spaces from string katmando Excel Worksheet Functions 4 May 16th 06 02:16 PM
Cells and and spaces after a string of text H Excel Worksheet Functions 2 November 19th 04 08:26 PM
Count Spaces In A String Josh in Tampa Excel Programming 2 October 23rd 03 05:59 PM


All times are GMT +1. The time now is 11:21 PM.

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"