Excel Count Functions
I like this idea better than my paramarray suggestion; however, I would
change your function slightly so the user would not have to know the syntax
of the Like operator...
Function Foo(A As Variant, P As String) As Double
Dim X As Variant
If Not TypeOf A Is Range And Not IsArray(A) Then A = Array(A)
For Each X In A
If X Like "*[" & P & "]*" Then Foo = Foo + 1
Next X
End Function
With this variation, all the user has to do is call the function like
this...
=Foo(A1:P1,"agm")
--
Rick (MVP - Excel)
"Harlan Grove" wrote in message
...
"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
....
Or make it general. Like
Function foo(a As Variant, p As String) As Double
Dim x As Variant
If Not TypeOf a Is Range And Not IsArray(a) Then a = Array(a)
For Each x In a
If x Like p Then foo = foo + 1
Next x
End Function
which could be used in formulas like
=foo(A1:P1,"*[agm]*")
This would allow counting any valid LIKE pattern.
|