View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Custom function to search a string of text for certain values

What was wrong with the answer. It doesn't work.

--
Regards,
Tom Ogilvy


"PapaDos" wrote in message
...
What is wrong with the answer ?

Thanks for the note about the parameter's name, I was a bit too quick...
--
Festina Lente


"Tom Ogilvy" wrote:

Think you need to test that. VBA doesn't support array interpretations
of
normal functions in most cases , this being one.

also str is a function in VBA, so poor choice as a variable.

You would need to use (Demo'd from the immediate window)

sStr = "the horse has a big head"
? Evaluate("Count(Find(Name1,""" & sstr & """))")
2


name1 was 3 cells containing the letters f a b
--
Regards,
Tom Ogilvy



"PapaDos" wrote in message
...
There is actually no need for a function, it can be done with an array
formula, but here it is:

Function rcmnf(str)
rcmnf = Application.Count(Application.Find([NF_range], str))
End Function
--
Festina Lente


"MikeCM" wrote:

I tried to put it into a custom function, called "rcmf". This
function would have a single argument, eqn1, being a single cell that
contains a big whole string of text made up of a series of values,
which are separated variously within the cell by spaces, parentheses,
etc..

I have a list of values elsewhere, a range of cells called NF_Range.
The function is intended to return a total of all the TRUE answers for
each test of the string against each of the values listed in NF_range
list.

The function was looking as follows:


Public Function rcmnf(eqn1)


Dim v is Array(NF_range)


'comment: where NF_range is the name given to a range of cells
containing the values I wish to check the "aggregate boolean
frequency"

of occurrence in the single cell the function points toward


For Each eqn1 In Selection


For i = LBound(v) To UBound(v)
cnt = Application.CountIf(cell, "*" & v(i) & "*")
totcnt = totcnt + cnt
Next


Next


End Function


When I say "aggregate boolean frequency" what I mean is take the first
value in NF_range and if it exists in the string on one or more
occasion(s), then count this as value 1 and move on to the next value
in NF_Range, and if that exists in the string on one or more
occasion(s), then count this as value 1 and add it to the previous
running total from the prior values checked in NF_Range, etc. etc.

I know this custom function isn't right, but I'm unsure about how to
proceed to
adapt your suggestion. Thank you for anyone providing thoughts
already.


Any further thoughts? Thanks.

Mike