Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 76
Default formula to count charcter in a range

needing a formulas that will count the charcter in a rnage
please advise
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default formula to count charcter in a range

LEN

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Dylan @ UAFC" wrote in message
...
needing a formulas that will count the charcter in a rnage
please advise


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 76
Default formula to count charcter in a range

Can you help wiht the range.
Got for a single cell, =len(a1)
no problem

but =LEN(a1:a100) returns #value

"Don Guillett" wrote:

LEN

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Dylan @ UAFC" wrote in message
...
needing a formulas that will count the charcter in a rnage
please advise



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default formula to count charcter in a range

Hi,

For a single cell try

=LEN(A1)

For a range of cells

=SUMPRODUCT(LEN(A1:A10))

Mike


"Dylan @ UAFC" wrote:

needing a formulas that will count the charcter in a rnage
please advise

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default formula to count charcter in a range

Dylan @ UAFC wrote:
needing a formulas that will count the charcter in a rnage
please advise



Your question is not exactly clear. See if this previous post helps...


Put this data in A1:A15:

down, DOWN, now, NOW, w, W, win, WIN, wow, WOW, www, WWW, AAA, BBB, CCC

Put w in B1. Depending upon what you want, use one of the formulas below (make
sure to commit the array-formulas with CTRL+SHIFT+ENTER).


1. Exact case as entire cell value (result = 1)

=SUM(--EXACT(A1:A15,B1))
*** array-formula ***



2. Either case as entire cell value (result = 2)

=COUNTIF(A1:A15,B1)



3. Starting with exact case (result = 4)

=SUM(--EXACT(LEFT(A1:A15,1),B1))
*** array-formula ***



4. Contains exact case (result = 6)

=COUNT(--(FIND(B1,A1:A15)0))
*** array-formula ***



5. Starting with either case (result = 8)

=SUM(--(LEFT(A1:A15,1)=B1))
*** array-formula ***



6. Total occurrences of exact case (result = 9)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(A1:A15,B1,"")))
*** array-formula ***



7. Contains either case (result = 12)

=COUNTIF(A1:A15,"*"&B1&"*")



8. Total occurrences of either case (result = 18)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(SUBSTITUTE(A1:A15,LOWER(B1),"") ,UPPER(B1),"")))
*** array-formula ***


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default formula to count charcter in a range

Glenn wrote...
....
sure to commit the array-formulas with CTRL+SHIFT+ENTER).

....

Or replace all SUM calls below with SUMPRODUCT and enter them as
regular formulas.

4. *Contains exact case (result = 6)

=COUNT(--(FIND(B1,A1:A15)0))


Inefficient. FIND will either be 0 or an error value, so

=COUNT(FIND(B1,A1:A15))

would be sufficient since it'll count only the positive numbers, not
the errors.

5. Starting with either case (result = 8)

=SUM(--(LEFT(A1:A15,1)=B1))


Inefficient. Use

=COUNTIF(A1:A15,B1&"*")

6. Total occurrences of exact case (result = 9)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(A1:A15,B1,"")))

....

Inefficient. Use

=SUMPRODUCT(LEN(A1:A15)-LEN(SUBSTITUTE(A1:A15,B1,"")))

8. Total occurrences of either case (result = 18)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(SUBSTITUTE(A1:A15,LOWER(B1),"") ,
UPPER(B1),"")))


Inefficient. Use

=SUMPRODUCT(LEN(A1:A15)-LEN(SUBSTITUTE(LOWER(A1:A15),LOWER(B1),"")))
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default formula to count charcter in a range

8. Total occurrences of either case (result = 18)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(SUBSTITUTE(A1:A15,LOWER(B1),"") ,UPPER(B1),"")))


Inefficient. Use

=SUMPRODUCT(LEN(A1:A15)-LEN(SUBSTITUTE(LOWER(A1:A15),LOWER(B1),"")))


How would this formula compare efficiency-wise?

=SUMPRODUCT(COUNTIF(A1:A15,"*"&REPT("w*",ROW(1:3)) ))

where the 1:3 could be expanded to 1:N where N would be the maximum number
of "w"s or "W"s that could appear in a single cell.

--
Rick (MVP - Excel)

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default formula to count charcter in a range

I'm guessing the answer will depend on the size of N. For example, when N is
3 as in this case, the SUMPRODUCT will only iterate 3 times, but if N were
100, then it would have to iterate 100 times. Your function will always
iterate the as many times as there are rows in the range. So, the more rows,
greater in number than N, the better I would think for my formula as
compared to yours. That probably means your answer to my original question
to you will be "it depends".<g

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
8. Total occurrences of either case (result = 18)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(SUBSTITUTE(A1:A15,LOWER(B1),"") ,UPPER(B1),"")))


Inefficient. Use

=SUMPRODUCT(LEN(A1:A15)-LEN(SUBSTITUTE(LOWER(A1:A15),LOWER(B1),"")))


How would this formula compare efficiency-wise?

=SUMPRODUCT(COUNTIF(A1:A15,"*"&REPT("w*",ROW(1:3)) ))

where the 1:3 could be expanded to 1:N where N would be the maximum number
of "w"s or "W"s that could appear in a single cell.

--
Rick (MVP - Excel)


  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default formula to count charcter in a range

There is code here that will test calculation times:

http://msdn2.microsoft.com/en-us/library/aa730921.aspx

I use it frequently.

--
Biff
Microsoft Excel MVP


"Rick Rothstein" wrote in message
...
I'm guessing the answer will depend on the size of N. For example, when N
is 3 as in this case, the SUMPRODUCT will only iterate 3 times, but if N
were 100, then it would have to iterate 100 times. Your function will
always iterate the as many times as there are rows in the range. So, the
more rows, greater in number than N, the better I would think for my
formula as compared to yours. That probably means your answer to my
original question to you will be "it depends".<g

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
8. Total occurrences of either case (result = 18)

=SUM(LEN(A1:A15))-SUM(LEN(SUBSTITUTE(SUBSTITUTE(A1:A15,LOWER(B1),"") ,UPPER(B1),"")))

Inefficient. Use

=SUMPRODUCT(LEN(A1:A15)-LEN(SUBSTITUTE(LOWER(A1:A15),LOWER(B1),"")))


How would this formula compare efficiency-wise?

=SUMPRODUCT(COUNTIF(A1:A15,"*"&REPT("w*",ROW(1:3)) ))

where the 1:3 could be expanded to 1:N where N would be the maximum
number of "w"s or "W"s that could appear in a single cell.

--
Rick (MVP - Excel)




  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default formula to count charcter in a range

"Rick Rothstein" wrote...
....

Changing arguments for clarity.

=SUMPRODUCT(LEN(range)-LEN(SUBSTITUTE(LOWER(range),LOWER(char),"")))


How would this formula compare efficiency-wise?

=SUMPRODUCT(COUNTIF(range,"*"&REPT(char&"*",insta nce_array)))

....

My formula would loop through range 5 times: the first LEN call, the
LOWER call, the SUBSTITITE call, the second LEN call, and the final
SUMPRODUCT call. However, my SUBSTITUTE call would only iterate
through range once, and perform a simple operation - effectively
deleting all w's.

Your formula would iterate through range as many times as there are
entries in instance array for the COUNTIF call, in your example 3
times. However, processing a range with COUNTIF where the second
argument contains wildcards isn't as simple as my SUBSTITUTE call. If
COUNTIF special cases patterns in which the first, last or both chars
are *, then COUNTIF should process the pattern "*w*" at least as fast
as SUBSTITUTE(range,"w","",1) would, and probably faster. However,
it's unlikely COUNTIF special cases patterns with *'s between literal
characters. When those occur, you need significantly more logic FOR
EACH entry in range, approximating an inner loop.

Your formula as you wrote it could effectively require 6 iterations
through range: once for "*w*", effectively 2 for "*w*w*", and
effectively 3 for "*w*w*w*". That is, if R were the number of entries
in range, A were the number of sequential entries in instance_array,
then my formula would be O(N) with a large constant (c), but yours
would be O(N A^2) with a small constant (d). As long as c d A^2,
yours would be faster. But as soon as c < d A^2, mine would be faster.
I'd guess yours would always be faster for A = 2, usually faster for A
= 3 except when most entries in range have at least 2 w's, and seldom
if ever faster for A = 4.


  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default formula to count charcter in a range

Thanks for the analysis. I assume that for this part...

Your formula as you wrote it could effectively require
6 iterations through range: once for "*w*", effectively
2 for "*w*w*", and effectively 3 for "*w*w*w*".

you use of the word "effectively" is meant to cover the fact that, for
example, in "*w*w*", once one 'w' is found, the search loop must continue on
in order to look for the next 'w'.

--
Rick (MVP - Excel)


"Harlan Grove" wrote in message
...
"Rick Rothstein" wrote...
...

Changing arguments for clarity.

=SUMPRODUCT(LEN(range)-LEN(SUBSTITUTE(LOWER(range),LOWER(char),"")))


How would this formula compare efficiency-wise?

=SUMPRODUCT(COUNTIF(range,"*"&REPT(char&"*",inst ance_array)))

...

My formula would loop through range 5 times: the first LEN call, the
LOWER call, the SUBSTITITE call, the second LEN call, and the final
SUMPRODUCT call. However, my SUBSTITUTE call would only iterate
through range once, and perform a simple operation - effectively
deleting all w's.

Your formula would iterate through range as many times as there are
entries in instance array for the COUNTIF call, in your example 3
times. However, processing a range with COUNTIF where the second
argument contains wildcards isn't as simple as my SUBSTITUTE call. If
COUNTIF special cases patterns in which the first, last or both chars
are *, then COUNTIF should process the pattern "*w*" at least as fast
as SUBSTITUTE(range,"w","",1) would, and probably faster. However,
it's unlikely COUNTIF special cases patterns with *'s between literal
characters. When those occur, you need significantly more logic FOR
EACH entry in range, approximating an inner loop.

Your formula as you wrote it could effectively require 6 iterations
through range: once for "*w*", effectively 2 for "*w*w*", and
effectively 3 for "*w*w*w*". That is, if R were the number of entries
in range, A were the number of sequential entries in instance_array,
then my formula would be O(N) with a large constant (c), but yours
would be O(N A^2) with a small constant (d). As long as c d A^2,
yours would be faster. But as soon as c < d A^2, mine would be faster.
I'd guess yours would always be faster for A = 2, usually faster for A
= 3 except when most entries in range have at least 2 w's, and seldom
if ever faster for A = 4.


  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default formula to count charcter in a range

Suppose the range is A1 thru A10.

=SUM(LEN(A1:A10))

This is an array formula that must be entered with CNTRL-SHFT-ENTER rather
than just the ENTER key.
--
Gary''s Student - gsnu200826


"Dylan @ UAFC" wrote:

needing a formulas that will count the charcter in a rnage
please advise

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
Formula to count every other column (dynamic range) Darlene New Users to Excel 7 November 18th 08 09:27 PM
count(if(... using array formula: can I use a named range in my ca katy Excel Worksheet Functions 1 January 15th 08 02:13 AM
How do I count the number of times a particular charcter ("." say) RH Excel Discussion (Misc queries) 2 December 8th 06 02:21 AM
Count formula within a named range. PW11111 Excel Discussion (Misc queries) 2 July 19th 05 09:29 AM
Formula to count only positives in range Stadinx Excel Discussion (Misc queries) 3 June 14th 05 08:10 AM


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