so I have a spreadsheet and I want to count how many instances of certain words there are in a range of cells. Usually with Excel formulae I can just do:
Countif(Range("D3:D20"), "*bob*")
And this will return the number of cells that contain "bob"
I was hoping to use this within VBA, and do it for all the words stored in an array. I tried:
x = Application.WorksheetFunction.Countif(Range("D3:D20"), "*array(i)*")
within a loop but it doesn't find any instances.
For completion,
x = Application.WorksheetFunction.Countif(Range("D3:D20"), "*bob*")
works as expected.
How can I pass the array elements as a string recognisable by the excel function? Thanks in advance
&like so:x = Application.WorksheetFunction.Countif(Range("D3:D20"), "*" & array(i) & "*")