PC Review


Reply
Thread Tools Rate Thread

Counting Specific Character(s) In A Range?

 
 
=?Utf-8?B?RkFSQVogUVVSRVNISQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
Can someone devise a formula to sum-up the number of times a character or
piece of string repeats in a range of cells?

For example:
[A1: When]
[A2: How]
[A3: Why]

When you apply such a formula on the range [A1:A3] for the character “W” it
gives you a reply of 3 (A1, A2 & A3) and when for “WH” it returns “2” (A1 &
A3).

Thanx in advance & Best Regards

 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      13th Sep 2007
If your range is fixed like you show, and if the text you want to find is in
B1, then you can use this...

=IF(B1<>"",(LEN(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3))-LEN(SUBSTITUTE(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3),UPPER(B1),"")))/LEN(B1),"")

Simply extend the concatenations to cover the maximum range you will have.
The CHAR(1) in-between the cell addresses are to make sure no false
positives are found (using "wh" for example, to make sure a cell doesn't end
with "w" and the next cell begin with "h"). We could have used a normal
character in place of the CHAR(1), but using CHAR(1) protects against that
character being in the "find" text.

Rick


"FARAZ QURESHI" <(E-Mail Removed)> wrote in message
news:422B8103-D581-4274-A639-(E-Mail Removed)...
> Can someone devise a formula to sum-up the number of times a character or
> piece of string repeats in a range of cells?
>
> For example:
> [A1: When]
> [A2: How]
> [A3: Why]
>
> When you apply such a formula on the range [A1:A3] for the character “W”
> it
> gives you a reply of 3 (A1, A2 & A3) and when for “WH” it returns “2” (A1
> &
> A3).
>
> Thanx in advance & Best Regards
>


 
Reply With Quote
 
=?Utf-8?B?RkFSQVogUVVSRVNISQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
YAHOOOOOOOOO!
Thanx Rick!!!
U R Great!!!!!

"Rick Rothstein (MVP - VB)" wrote:

> If your range is fixed like you show, and if the text you want to find is in
> B1, then you can use this...
>
> =IF(B1<>"",(LEN(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3))-LEN(SUBSTITUTE(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3),UPPER(B1),"")))/LEN(B1),"")
>
> Simply extend the concatenations to cover the maximum range you will have.
> The CHAR(1) in-between the cell addresses are to make sure no false
> positives are found (using "wh" for example, to make sure a cell doesn't end
> with "w" and the next cell begin with "h"). We could have used a normal
> character in place of the CHAR(1), but using CHAR(1) protects against that
> character being in the "find" text.
>
> Rick
>
>
> "FARAZ QURESHI" <(E-Mail Removed)> wrote in message
> news:422B8103-D581-4274-A639-(E-Mail Removed)...
> > Can someone devise a formula to sum-up the number of times a character or
> > piece of string repeats in a range of cells?
> >
> > For example:
> > [A1: When]
> > [A2: How]
> > [A3: Why]
> >
> > When you apply such a formula on the range [A1:A3] for the character “W”
> > it
> > gives you a reply of 3 (A1, A2 & A3) and when for “WH” it returns “2” (A1
> > &
> > A3).
> >
> > Thanx in advance & Best Regards
> >

>
>

 
Reply With Quote
 
=?Utf-8?B?RkFSQVogUVVSRVNISQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
By the way Rick! If there isn't any repetition of same character in one cell.
Any idea of using some sort of sumproduct() funtion like:

=Sumproduct(--(find("W",A1:A3)>0))?

Concatenations of a large range otherwise would take too much length and
formula would not be possible.

The strategy presented former however I do still accept was outstanding and
truly a GREAT one!

"Rick Rothstein (MVP - VB)" wrote:

> If your range is fixed like you show, and if the text you want to find is in
> B1, then you can use this...
>
> =IF(B1<>"",(LEN(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3))-LEN(SUBSTITUTE(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3),UPPER(B1),"")))/LEN(B1),"")
>
> Simply extend the concatenations to cover the maximum range you will have.
> The CHAR(1) in-between the cell addresses are to make sure no false
> positives are found (using "wh" for example, to make sure a cell doesn't end
> with "w" and the next cell begin with "h"). We could have used a normal
> character in place of the CHAR(1), but using CHAR(1) protects against that
> character being in the "find" text.
>
> Rick
>
>
> "FARAZ QURESHI" <(E-Mail Removed)> wrote in message
> news:422B8103-D581-4274-A639-(E-Mail Removed)...
> > Can someone devise a formula to sum-up the number of times a character or
> > piece of string repeats in a range of cells?
> >
> > For example:
> > [A1: When]
> > [A2: How]
> > [A3: Why]
> >
> > When you apply such a formula on the range [A1:A3] for the character “W”
> > it
> > gives you a reply of 3 (A1, A2 & A3) and when for “WH” it returns “2” (A1
> > &
> > A3).
> >
> > Thanx in advance & Best Regards
> >

>
>

 
Reply With Quote
 
=?Utf-8?B?UXVsbDY2NkBob3RtYWlsLmNvbQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
Dear Rick,

I am just being nosy and this thread is of interest to me. I was wondering
if the data extended to say 100 rows, is it possible to count the specific
characters.

Thanks.



 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      13th Sep 2007
If you have a large range, and if there could be repeats within a cell, you
could do this instead. Assuming your text phrases are in column A and B1
holds the text you want to search for, put this formula

=SUMPRODUCT(--ISNUMBER(SEARCH(MID(A1,ROW(INDIRECT("A$1:A"&LEN(A1))),LEN($B$1)),$B$1)))

in a blank column and copy it down. What the formula does is list the number
of times the text in B1 appears in each cell in column A; so, to get your
total, just SUM up the column you placed the above formulas in. If you don't
want to show these individual counts, hide the column and put your SUM
formula in a different column

Rick


"FARAZ QURESHI" <(E-Mail Removed)> wrote in message
news:E29F975E-6678-4919-98F3-(E-Mail Removed)...
> By the way Rick! If there isn't any repetition of same character in one
> cell.
> Any idea of using some sort of sumproduct() funtion like:
>
> =Sumproduct(--(find("W",A1:A3)>0))?
>
> Concatenations of a large range otherwise would take too much length and
> formula would not be possible.
>
> The strategy presented former however I do still accept was outstanding
> and
> truly a GREAT one!
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> If your range is fixed like you show, and if the text you want to find is
>> in
>> B1, then you can use this...
>>
>> =IF(B1<>"",(LEN(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3))-LEN(SUBSTITUTE(UPPER(A1&CHAR(1)&A2&CHAR(1)&A3),UPPER(B1),"")))/LEN(B1),"")
>>
>> Simply extend the concatenations to cover the maximum range you will
>> have.
>> The CHAR(1) in-between the cell addresses are to make sure no false
>> positives are found (using "wh" for example, to make sure a cell doesn't
>> end
>> with "w" and the next cell begin with "h"). We could have used a normal
>> character in place of the CHAR(1), but using CHAR(1) protects against
>> that
>> character being in the "find" text.
>>
>> Rick
>>
>>
>> "FARAZ QURESHI" <(E-Mail Removed)> wrote in message
>> news:422B8103-D581-4274-A639-(E-Mail Removed)...
>> > Can someone devise a formula to sum-up the number of times a character
>> > or
>> > piece of string repeats in a range of cells?
>> >
>> > For example:
>> > [A1: When]
>> > [A2: How]
>> > [A3: Why]
>> >
>> > When you apply such a formula on the range [A1:A3] for the character
>> > “W”
>> > it
>> > gives you a reply of 3 (A1, A2 & A3) and when for “WH” it returns “2”
>> > (A1
>> > &
>> > A3).
>> >
>> > Thanx in advance & Best Regards
>> >

>>
>>


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      13th Sep 2007
> If you have a large range, and if there could be repeats within a cell,
> you could do this instead. Assuming your text phrases are in column A and
> B1 holds the text you want to search for, put this formula
>
> =SUMPRODUCT(--ISNUMBER(SEARCH(MID(A1,ROW(INDIRECT("A$1:A"&LEN(A1))),LEN($B$1)),$B$1)))
>
> in a blank column and copy it down. What the formula does is list the
> number of times the text in B1 appears in each cell in column A; so, to
> get your total, just SUM up the column you placed the above formulas in.
> If you don't want to show these individual counts, hide the column and put
> your SUM formula in a different column.


Never mind... don't use this formula, it fails under certain circumstances.

Rick

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      13th Sep 2007
>> If you have a large range, and if there could be repeats within a cell,
>> you could do this instead. Assuming your text phrases are in column A and
>> B1 holds the text you want to search for, put this formula
>>
>> =SUMPRODUCT(--ISNUMBER(SEARCH(MID(A1,ROW(INDIRECT("A$1:A"&LEN(A1))),LEN($B$1)),$B$1)))
>>
>> in a blank column and copy it down. What the formula does is list the
>> number of times the text in B1 appears in each cell in column A; so, to
>> get your total, just SUM up the column you placed the above formulas in.
>> If you don't want to show these individual counts, hide the column and
>> put your SUM formula in a different column.

>
> Never mind... don't use this formula, it fails under certain
> circumstances.


This formula works...

=SUMPRODUCT(--ISNUMBER(SEARCH(MID(A1&"|",ROW(INDIRECT("A$1:A"&LEN(A1))),LEN($B$1)),$B$1)))

Any character concatenated on the end of the text in the cell being searched
(I used the vertical bar), as long as that character will never appear in
your text, stops the miscount. So, use the above formula, copy it down and
SUM the result as I described in my second post.

Rick

 
Reply With Quote
 
=?Utf-8?B?RkFSQVogUVVSRVNISQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
Hey Guys!

CHIP PEARSON has justhelped me in an xclent development in this regard i.e.:

For single character
=SUM(LEN(A1:A3)-LEN(SUBSTITUTE(UPPER(A1:A3),UPPER("w"),"")))

& for string:
=SUM(LEN(A1:A3)-LEN(SUBSTITUTE(UPPER(A1:A3),UPPER("wh"),"")))/LEN("wh")

"(E-Mail Removed)" wrote:

> Dear Rick,
>
> I am just being nosy and this thread is of interest to me. I was wondering
> if the data extended to say 100 rows, is it possible to count the specific
> characters.
>
> Thanks.
>
>
>

 
Reply With Quote
 
=?Utf-8?B?RHVrZSBDYXJleQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
You can also use

=SUMPRODUCT(--(LEN(A1:A3)>LEN(SUBSTITUTE(UPPER(A1:A3),"W",""))))

"FARAZ QURESHI" wrote:

> Hey Guys!
>
> CHIP PEARSON has justhelped me in an xclent development in this regard i.e.:
>
> For single character
> =SUM(LEN(A1:A3)-LEN(SUBSTITUTE(UPPER(A1:A3),UPPER("w"),"")))
>
> & for string:
> =SUM(LEN(A1:A3)-LEN(SUBSTITUTE(UPPER(A1:A3),UPPER("wh"),"")))/LEN("wh")
>
> "(E-Mail Removed)" wrote:
>
> > Dear Rick,
> >
> > I am just being nosy and this thread is of interest to me. I was wondering
> > if the data extended to say 100 rows, is it possible to count the specific
> > characters.
> >
> > Thanks.
> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting a Specific Character FARAZ QURESHI Microsoft Excel Misc 2 27th Apr 2009 11:07 AM
Re: Counting specific character in text string JE McGimpsey Microsoft Excel Worksheet Functions 0 18th Jan 2007 08:36 PM
Counting the number of times a specific character appears in a cell PCLIVE Microsoft Excel Worksheet Functions 3 4th Nov 2005 05:08 AM
Counting cells with a specific range =?Utf-8?B?dGVyZXNh?= Microsoft Excel Programming 1 8th Aug 2005 12:18 PM
Counting a specific character in columns deepkris Microsoft Excel Misc 2 30th Jul 2004 02:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 PM.