Try something like
Function CountLetters(InRange As Range, S As String) As Long
Dim Rng As Range
For Each Rng In InRange
CountLetters = CountLetters + Len(Rng.Text) - _
Len(Replace(Rng.Text, S, "", , , vbTextCompare))
Next Rng
End Function
Then call this with from a cell with =CountLetters(A1:A5,"s") or in VBA with
code like
MsgBox "There are " & CountLetters(Range("A1:A5"), "s") & " letters found."
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Jim Brass" <jbr...@cfu.net> wrote in message news:a0a1t5$mf2$1...@news.cfu.net...
one possible way, assume that the states are in A1:A50, in B1 put
=CHAR(97+ROW(1:1)-1)
drag the fillhandle to copy it down to B26
in C1 put
=SUM(LEN($A$1:$A$50)-(LEN(SUBSTITUTE(LOWER($A$1:$A$50),B1,""))))
enter it with Ctrl+Shift&Enter and double click the lower right corner of C1
Now you should have a list starting with number of "a(s)" regardless of
upper or lower case going down to "z"..
-
Regards,
Peo Sjoblom
"Jim Brass" <jbr...@cfu.net> wrote in message
news:a0a1t5$mf2$1...@news.cfu.net...
This Function hangs on me at "Replace". "Sub or Function not defined". I can
use the REPLACE function on its own in a cell.
Do I need to add a Reference to something? Maybe another eggnog would help??
Thanks, Gord Dibben Excel MVP - XL97 SR2
Replace was added in VBA6 (Office2000). You can use the Excel Substitute
function instead.
For Each Rng In InRange
CountLetters = CountLetters + Len(Rng.Text) - _
Len(Application.WorksheetFunction.Substitute(UCase(Rng.Text), UCase(S),
""))
Next Rng
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Gord Dibben" <gdi...@shaw.ca> wrote in message
news:c4gh2u8a2qvj0757g...@4ax.com...
Does the trick. Just gonna have to upgrade one of these days.
Gord
"Peo Sjoblom" <ter...@yahoo.com> wrote in message
news:e3iNb3WjBHA.4596@tkmsftngp04...
=CHAR(65+ROW(1:1)-1)
will give you uppercase letters
and yes you can change lower to upper in the formula if the letters in the
list are caps, or you can bypass that by using
=SUM(LEN($A$1:$A$50)-(LEN(SUBSTITUTE(UPPER($A$1:$A$50),UPPER(B1),""))))
(or use lower in both instances) will work regardless of upper/lower case
in the letter list
--
Regards,
Peo Sjoblom
"Jim Brass" <jbr...@cfu.net> wrote in message
news:a0ap80$o59$1...@news.cfu.net...
"Peo Sjoblom" <ter...@yahoo.com> wrote in message
news:eokZ6hYjBHA.4792@tkmsftngp04...