Format and Color Text in Excel Cell with VBA

Formatting a substring of a string in an Excel Cell is actually quite a challenging task. There are two ways to do it – select part of the substring that you wish to format and change its color. Then make it Bold, Italic or Underline like this:

However, there is a second, better way – use VBA and check every value after the substring for eligibility. If the substring is eligible, then simply format it. In our case, we would like to format anything numeric after importance=”, tid=” and index=”.

Thus, we need to search for every single character until the found substring and check whether it is numeric. If this is the case, format the character in the specific color and type. This should be enough:

Quite small, but it works!

Cheers!

About

VBA Developer

Tagged with: , ,