No problems.
I'd do this one like this*...
Sub CountByWord()
Const lWORD_COLUMN = 2
Const lROW_OFFSET = 0
Const lCOL_OFFSET = -1
Dim sWordToMatch As String 'Avoid using single letters for your variable names. It makes your code hard to read
Dim lCount As Long
Dim rngMatchWord As Range
Dim sFirstAddress As String
sWordToMatch = InputBox("Please enter word to match")
If sWordToMatch <> "" Then
lCount = 0
Set rngMatchWord = Columns(lWORD_COLUMN).Find(sWordToMatch, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not rngMatchWord Is Nothing Then
sFirstAddress = rngMatchWord.Address
Do
lCount = lCount + rngMatchWord.Offset(lROW_OFFSET, lCOL_OFFSET).Value
Set rngMatchWord = Columns(lWORD_COLUMN).Find(sWordToMatch, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False, after:=rngMatchWord)
Loop Until rngMatchWord.Address = sFirstAddress
End If
MsgBox "Count = " & lCount
End If
End Sub
However a lot of new coders would go through their worksheet row by row, checking each value. This can be very slow indeed for larger sheets.
* This is a lie, I'd use WorksheetFunction.SumIf to implement the formula I wrote up above, but if I'd forgotten how to do that then I'd do things as above. Probably
Bookmarks