I don't have anything for you Niek.
But I think I've seen some posts where people who know regular expressions have
taken a whack at it using a UDF.
Me...I'd just try to come up with a list of characters that can be surrounding
that word and change them to spaces, then look for the word surrounded by
spaces.
or even look the valid characters -- say they could only be a-z, then you could
do the same kind of thing in reverse. If it's not a-z, then change it to a
space.
Option Explicit
Function myCountif(rng As Range, myWord As String) As Long
Dim myCell As Range
Dim myStr As String
Dim iCtr As Long
Dim myTotal As Long
myTotal = 0
For Each myCell In rng.Cells
myStr = LCase(myCell.Value)
For iCtr = 1 To Len(myStr)
If Mid(myStr, iCtr, 1) Like "[a-z]" Then
'keep it
Else
Mid(myStr, iCtr, 1) = " "
End If
Next iCtr
myStr = " " & myStr & " "
If InStr(1, myStr, " " & myWord & " ", vbTextCompare) Then
myTotal = myTotal + 1
End If
Next myCell
myCountif = myTotal
End Function
Niek said:
I've been trying to cope with more than one instance of the word in one cell
and with real "words", that is, surrounded by spaces, punctuation, brackets,
begin/end-of string, etc.
I'm not at all near to finishing that.
Does anyone have anything to give me a jump-start?