Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default How to Count String occurences

Excel 2003. Is there a quick way (a function perhaps) to count the number of
occurences of a substring within a string? I have address strings in which I
want to quickly count the number of occurences of a double space (" ") in
the string. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to Count String occurences

Try something like the following:


Dim S As String
Dim SearchString As String
Dim SubStringCount As Integer
S = "the quick brown fox"
SearchString = " " ' two spaces
SubStringCount = (Len(S) - Len(Replace(S, SearchString, ""))) /
Len(SearchString)
Debug.Print SubStringCount


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Chaplain Doug" wrote in
message
...
Excel 2003. Is there a quick way (a function perhaps) to count
the number of
occurences of a substring within a string? I have address
strings in which I
want to quickly count the number of occurences of a double
space (" ") in
the string. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default How to Count String occurences

Thanks for the cool tip. Did you guys study mathematics? I've got degrees
in it, but my doltish brain didn't think of this. I AM getting old! God
bless.

"Chip Pearson" wrote:

Try something like the following:


Dim S As String
Dim SearchString As String
Dim SubStringCount As Integer
S = "the quick brown fox"
SearchString = " " ' two spaces
SubStringCount = (Len(S) - Len(Replace(S, SearchString, ""))) /
Len(SearchString)
Debug.Print SubStringCount


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Chaplain Doug" wrote in
message
...
Excel 2003. Is there a quick way (a function perhaps) to count
the number of
occurences of a substring within a string? I have address
strings in which I
want to quickly count the number of occurences of a double
space (" ") in
the string. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to Count String occurences

As a matter of fact, I do have a degree in mathematics. Haven't
used it in years, though.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chaplain Doug" wrote in
message
...
Thanks for the cool tip. Did you guys study mathematics? I've
got degrees
in it, but my doltish brain didn't think of this. I AM getting
old! God
bless.

"Chip Pearson" wrote:

Try something like the following:


Dim S As String
Dim SearchString As String
Dim SubStringCount As Integer
S = "the quick brown fox"
SearchString = " " ' two spaces
SubStringCount = (Len(S) - Len(Replace(S, SearchString, "")))
/
Len(SearchString)
Debug.Print SubStringCount


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Chaplain Doug" wrote
in
message
...
Excel 2003. Is there a quick way (a function perhaps) to
count
the number of
occurences of a substring within a string? I have address
strings in which I
want to quickly count the number of occurences of a double
space (" ") in
the string. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org






  #5   Report Post  
Posted to microsoft.public.excel.programming
bj bj is offline
external usenet poster
 
Posts: 1,397
Default How to Count String occurences

If you are sure there are no space multiples greater than 2 you can use
=(len(a1)-len(substitute(a1," ",""))/2

"Chaplain Doug" wrote:

Excel 2003. Is there a quick way (a function perhaps) to count the number of
occurences of a substring within a string? I have address strings in which I
want to quickly count the number of occurences of a double space (" ") in
the string. Thanks for the help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org



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
Count occurences in string Ken Excel Discussion (Misc queries) 3 June 10th 09 08:29 PM
SUMPRODUCT to calculate unique occurences of string in column of d WildWill Excel Discussion (Misc queries) 3 April 3rd 09 03:16 PM
Count # of Occurences Sweepea Excel Discussion (Misc queries) 6 December 14th 06 02:27 AM
Count occurences AvalancheMike Excel Programming 4 January 24th 05 11:07 PM
count number of occurences within a string Gabriel Excel Worksheet Functions 2 November 25th 04 04:17 PM


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

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

About Us

"It's about Microsoft Excel"