excel – Search for specific word in VBA string

excel – Search for specific word in VBA string

You could also use Regular Expressions to achieve this in VBA.

Looking specifically at the ^ and $ operators to force the full word match.

So in your case something like ^Egg$ as the pattern should do what you want.

See here for some good help on this:
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

InStr is the way to go. For finding out how many times a string is present in a text, you can use this one-line code. Here I use your example.

Debug.Print UBound(Split(Eggplant Pizza, Egg))

To make the code case insensitive, you can put Option Compare Text on top of your code module.

excel – Search for specific word in VBA string

Leave a Reply

Your email address will not be published. Required fields are marked *