In this blog post, we look at how to create a macro that will look in a list and format all the instances of specific words that appear in a cell.
This macro is case sensitive and will also only apply the formatting if it is the whole word. For example, if you are formatting all instances of the word ‘red’, this macro will not format it if used in words like ‘reddish’ and ‘sacred’.
The macro uses a For Each Next loop to work on the range of cells selected by a user.
The Characters property has been used to apply the formatting to only specific words in a cell. In order to work, the Characters property will need the position of the first character of the word, and also how many characters to format.
The InStr function was used to find the first character of the word, or words, in each cell.
A Do loop is used to check the whole cell so if the word occurs multiple times in a cell, each instance is formatted.
Here is the complete Excel VBA macro code used.
[Read more…] about Format Specific Words in a Cell using VBA