Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default counting the number of instances of a string within another string

I'm sure there is an easy way to do this; I just haven't had to do it before
so I'm not sure what the most elegant solution is.

I have a column of values, and within each cell, there are an unknown number
of commas (e.g. "323,76,12,43"). I need to identify (for each cell, in the
next column over) how many commas are present. The basic instr or match type
functions (I think) only provide the first match location, not a total
number of matches. Maybe something like the opposite of REPT, only something
that ignores all the other text and just gives the count of the target
string that is already repeated in the cell.

Any suggestions on a preferred approach?

Thank you,
Keith



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default counting the number of instances of a string within another string

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

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Keith R" wrote in message
...
I'm sure there is an easy way to do this; I just haven't had to do it
before so I'm not sure what the most elegant solution is.

I have a column of values, and within each cell, there are an unknown
number of commas (e.g. "323,76,12,43"). I need to identify (for each cell,
in the next column over) how many commas are present. The basic instr or
match type functions (I think) only provide the first match location, not
a total number of matches. Maybe something like the opposite of REPT, only
something that ignores all the other text and just gives the count of the
target string that is already repeated in the cell.

Any suggestions on a preferred approach?

Thank you,
Keith





  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default counting the number of instances of a string within another string

Try this:

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

Biff

"Keith R" wrote in message
...
I'm sure there is an easy way to do this; I just haven't had to do it
before so I'm not sure what the most elegant solution is.

I have a column of values, and within each cell, there are an unknown
number of commas (e.g. "323,76,12,43"). I need to identify (for each cell,
in the next column over) how many commas are present. The basic instr or
match type functions (I think) only provide the first match location, not
a total number of matches. Maybe something like the opposite of REPT, only
something that ignores all the other text and just gives the count of the
target string that is already repeated in the cell.

Any suggestions on a preferred approach?

Thank you,
Keith





  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 55
Default counting the number of instances of a string within another string

Excellent, thank you Bob and Biff!


"Bob Phillips" wrote in message
...
=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Keith R" wrote in message
...
I'm sure there is an easy way to do this; I just haven't had to do it
before so I'm not sure what the most elegant solution is.

I have a column of values, and within each cell, there are an unknown
number of commas (e.g. "323,76,12,43"). I need to identify (for each
cell, in the next column over) how many commas are present. The basic
instr or match type functions (I think) only provide the first match
location, not a total number of matches. Maybe something like the
opposite of REPT, only something that ignores all the other text and just
gives the count of the target string that is already repeated in the
cell.

Any suggestions on a preferred approach?

Thank you,
Keith







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
Counting the appearance of a String in a Row [email protected] Excel Worksheet Functions 2 October 3rd 06 02:51 PM
Splitting a text string into string and number mcambrose Excel Discussion (Misc queries) 4 February 21st 06 03:47 PM
Counting number of time a character appears in a string Henrik Excel Worksheet Functions 5 October 20th 05 11:00 PM
Countif function for instances of text string contained Garbunkel Excel Worksheet Functions 1 October 11th 05 08:09 AM
Countif function for instances of text string contained David Billigmeier Excel Worksheet Functions 2 October 10th 05 09:51 PM


All times are GMT +1. The time now is 01:55 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"