View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Excel Count Functions

Thanks rick,

I continually miss the option of putting values in an array and using Like.

Mike

"Rick Rothstein" wrote:

You can simplify your function like this...

Function CountChr(Rng As Range, C1 As String, _
C2 As String, C3 As String) As Long
Dim C As Range
For Each C In Rng
If C.Value Like "*[" & C1 & C2 & C3 & "]*" Then CountChr = CountChr + 1
Next
End Function

Note I shortened the name of your function and some of your argument names
in order to prevent newsreaders from word-wrapping the long If-Then
statement.

--
Rick (MVP - Excel)


"Mike H" wrote in message
...
Someone must be able to do better than this

call with

=CountChar(B2:E2,"a","b","c")

Function CountChar(rng As Range, ch1 As String, ch2 As String, ch3 As
String) As Long
For Each c In rng
If InStr(UCase(c.Value), UCase(ch1)) Then CountChar = CountChar + 1
If InStr(UCase(c.Value), UCase(ch2)) Then CountChar = CountChar + 1
If InStr(UCase(c.Value), UCase(ch3)) Then CountChar = CountChar + 1
Next
End Function

Mike

"Gary Mc" wrote:

My bad, you are absolutely correct. I apologize for the error!

"David Biddulph" wrote:

Won't that double count if the cell contains both a and x?
--
David Biddulph

"Gary Mc" wrote in message
...
I'm sure there are other and probably better solutions but this will
work
=SUM(COUNTIF(B2:E2,"*a*"),COUNTIF(B2:E2,"*x*"))
Hope this is helpful
GMc

"Gasbag" wrote:

I am trying to count the number of cells in a row that contain one
or
more of
three letters?