Format and Change Text
Changing the appearance of text in cells is one of the most common operations when you are working with a worksheet. You can spend hours getting your worksheet to look just the way you like.
When you want to use code to set or change the format of text in a cell, you have two choices:
Use the
Fontproperty to return aFont object, which lets you set or change the format of the entire cell.Use the
Characterscollection to set or change the format of individual characters within a cell.
The following code uses the Font property to format the cells in the specified range in bold type:
ActiveSheet.Range("A1:A7").Font.Bold = TrueThe following code uses the Characters collection to change the font to bold type for the first six characters in cell A7. For example, if the first word in the cell is “urgent,” the following code displays only that word in bold type:
ActiveSheet.Range("A9").Characters(1, 6).Font.Bold = TrueBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access