In this VBA Tutorial, you learn how to change or set the font characteristics of a cell range.
This VBA Font Tutorial is accompanied by Excel workbooks containing the data and macros I use in the examples below. You can get immediate free access to these example workbooks by subscribing to the Power Spreadsheets Newsletter.
Use the following Table of Contents to navigate to the section you're interested in.
Table of Contents
Related Excel VBA and Macro Tutorials
The following VBA and Macro Tutorials may help you better understand and implement the contents below:
- General VBA constructs and structures:
- Learn the basics of how to work with macros here.
- Learn about essential VBA terms here.
- Learn how to enable and disable macros here.
- Learn how to work with the Visual Basic Editor (VBE) here.
- Learn how to create object references here.
- Learn about the R1C1-style system here.
- Learn how to create Sub procedures here.
- Learn how to declare and work with variables here.
- Learn how to work with VBA data types here.
- Learn how to work with object properties here.
- Learn how to work with functions in VBA here.
- Learn how to work with loops here.
- Practical VBA applications and macro examples:
- Learn how to refer to worksheets here.
- Learn how to refer to cell ranges here.
- Learn how to find the last row in a worksheet here.
- Learn how to find the last column in a worksheet here.
- Learn how to specify a column's width here.
- Learn how to identify empty cells here.
- Learn how to clear a cell here.
You can find additional VBA and Macro Tutorials in the Archives.
#1: Change or set font with theme fonts
VBA code to change or set font with theme fonts
To change or set the font by referring to the applicable theme fonts, use a statement with the following structure:
Range.Font.ThemeFont = xlThemeFontConstant
Process to change or set font with theme fonts
To change or set the font by referring to the applicable theme fonts, follow these steps:
- Identify the cell range whose font you modify (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.ThemeFont property to an xlThemeFont constant (Font.ThemeFont = xlThemeFontConstant), which specifies the theme font to be used.
VBA statement explanation
Item: Range
Range object representing the cell range whose font you modify.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: ThemeFont
The Font.ThemeFont property sets the font by referring to the applicable theme fonts.
Item: =
The assignment operator assigns a new value (xlThemeFontConstant) to the Font.ThemeFont property.
Item: xlThemeFontConstant
The constants in the xlThemeFont enumeration specify the theme font. Therefore, set the Font.ThemeFont property to one of the following xlThemeFont constants:
xlThemeFont constant | Value | Description |
xlThemeFontMajor | 2 | Major theme font |
xlThemeFontMinor | 1 | Minor theme font |
xlThemeFontNone | 0 | Don't use a theme font |
Macro example to change or set font with theme fonts
The following macro example sets the font in cell A5 (Range(“A5”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to the major theme font (font.ThemeFont = xlThemeFontMajor).
Sub fontThemeFont() 'Source: https://powerspreadsheets.com/ 'sets the font by referring to applicable theme fonts 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the theme font from the applied font scheme ThisWorkbook.Worksheets("VBA Font").Range("A5").font.ThemeFont = xlThemeFontMajor End Sub
Effects of executing macro example to change or set font with theme fonts
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font of cell A5 to the major theme font.
#2: Change or set font name
VBA code to change or set font name
To change or set the font name, use a statement with the following structure:
Range.Font.Name = "FontName"
Process to change or set font name
To change or set the font name, follow these steps:
- Identify the cell range whose font you name you change (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Name property to a string specifying the font you use (Font.Name = “FontName”).
VBA statement explanation
Item: Range
Range object representing the cell range whose font name you change.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Name
The Font.Name property sets the font's name.
Item: =
The assignment operator assigns a new value (“FontName”) to the Font.Name property.
Item: “FontName”
Set the Font.Name property to a string specifying the font you use (FontName).
If you explicitly declare a variable to represent “FontName”, work with the String data type.
Macro example to change or set font name
The following macro example sets the font in cell A6 (Range(“A6”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to Verdana (font.Name = “Verdana”).
Sub fontName() 'Source: https://powerspreadsheets.com/ 'sets the font 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the font name ThisWorkbook.Worksheets("VBA Font").Range("A6").font.Name = "Calibri" End Sub
Effects of executing macro example to change or set font name
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font of cell A6 to Verdana.
#3: Change or set font size
VBA code to change or set font size
To change or set the font size, use a statement with the following structure:
Range.Font.Size = FontSize#
Process to change or set font size
To change or set the font size, follow these steps:
- Identify the cell range whose font size you change (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Size property to a number specifying the size (in points) of the font you use (Font.Size = FontSize#).
VBA statement explanation
Item: Range
Range object representing the cell range whose font size you change.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Size
The Font.Size property sets the font's size.
Item: =
The assignment operator assigns a new value (FontSize#) to the Font.Size property.
Item: FontSize#
Set the Font.Size property to a number specifying the size (in points) of the font you use (FontSize#).
Macro example to change or set font size
The following macro example sets the font size of cell A7 (Range(“A7”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to 13 (font.Size = 13).
Sub fontSize() 'Source: https://powerspreadsheets.com/ 'sets the font size 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the font size ThisWorkbook.Worksheets("VBA Font").Range("A7").font.Size = 13 End Sub
Effects of executing macro example to change or set font size
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font size of cell A7 to 13.
#4: Change or set font style
VBA code to change or set font style
To change or set the font style, use a statement with the following structure:
Range.Font.FontStyle = "FontStyle"
Process to change or set font style
To change or set the font style, follow these steps:
- Identify the cell range whose font you style you change (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Style property to a string specifying the font style you use (Font.FontStyle = “FontStyle”).
VBA statement explanation
Item: Range
Range object representing the cell range whose font style you change.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: FontStyle
The Font.FontStyle property sets the font style.
Item: =
The assignment operator assigns a new value (“FontStyle”) to the Font.FontStyle property.
Item: “FontStyle”
Set the Font.FontStyle property to one of the following strings (FontStyle):
- Regular;
- Italic;
- Bold; or
- Bold Italic.
Macro example to change or set font style
The following macro example sets the font style of cell A8 (Range(“A8”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to bold and italic (font.fontStyle = “Bold Italic”).
Sub fontStyle() 'Source: https://powerspreadsheets.com/ 'sets the font style 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the font style ThisWorkbook.Worksheets("VBA Font").Range("A8").font.fontStyle = "Bold Italic" End Sub
Effects of executing macro example to change or set font style
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font style of cell A8 to bold and italic.
#5: Set font bold
VBA code to set font bold
To set the font to bold, use a statement with the following structure:
Range.Font.Bold = True
Process to set font bold
To set the font to bold, follow these steps:
- Identify the cell range whose font you set to bold (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Bold property to True (Font.Bold = True).
VBA statement explanation
Item: Range
Range object representing the cell range whose font you set to bold.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Bold
The Font.Bold property sets the font to bold (or not bold).
Item: =
The assignment operator assigns a new value (True) to the Font.Bold property.
Item: True
To make the font bold, set the Font.Bold property to True.
To remove the font's bold formatting, set the Font.Bold property to False.
Macro example to set font bold
The following macro example makes the font of cell A9 (Range(“A9”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) bold (font.Bold = True).
Sub fontBold() 'Source: https://powerspreadsheets.com/ 'sets font to bold 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'make font bold ThisWorkbook.Worksheets("VBA Font").Range("A9").font.Bold = True End Sub
Effects of executing macro example to set font bold
The following GIF illustrates the results of executing the macro example. As expected, Excel makes the font of cell A9 bold.
#6: Set font italic
VBA code to set font italic
To set the font to italic, use a statement with the following structure:
Range.Font.Italic = True
Process to set font italic
To set the font to italic, follow these steps:
- Identify the cell range whose font you set to italic (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Italic property to True (Font.Italic = True).
VBA statement explanation
Item: Range
Range object representing the cell range whose font you set to italic.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Italic
The Font.Italic property sets the font to italic (or not italic).
Item: =
The assignment operator assigns a new value (True) to the Font.Italic property.
Item: True
To make the font italic, set the Font.Italic property to True.
To remove the font's italic formatting, set the Font.Bold property to False.
Macro example to set font italic
The following macro example makes the font of cell A10 (Range(“A10”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) italic (font.Italic = True).
Sub fontItalic() 'Source: https://powerspreadsheets.com/ 'sets font style to italic 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'make font italic ThisWorkbook.Worksheets("VBA Font").Range("A10").font.Italic = True End Sub
Effects of executing macro example to set font italic
The following GIF illustrates the results of executing the macro example. As expected, Excel makes the font of cell A10 italic.
#7: Set font underline
VBA code to set font underline
To underline the font, use a statement with the following structure:
Range.Font.Underline = xlUnderlineStyleConstant
Process to set font underline
To underline the font, follow these steps:
- Identify the cell range whose font you underline (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Underline property to an xlUnderlineStyle constant (Font.Underline = xlUnderlineStyleConstant), which specifies the type of font underline.
VBA statement explanation
Item: Range
Range object representing the cell range whose font you underline.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Underline
The Font.Underline property sets the type of font underline.
Item: =
The assignment operator assigns a new value (xlUnderlineStyleConstant) to the Font.Underline property.
Item: xlUnderlineStyleConstant
The constants in the xlUnderlineStyle enumeration specify the type of font underline. Therefore, set the Font.Underline property to one of the following xlUnderlineStyle constants:
xlUnderlineStyle constant | Value |
xlUnderlineStyleDouble | -4119 |
xlUnderlineStyleDoubleAccounting | 5 |
xlUnderlineStyleNone | -4142 |
xlUnderlineStyleSingle | 2 |
xlUnderlineStyleSingleAccounting | 4 |
Macro example to set font underline
The following macro example underlines with a double line (font.Underline = xlUnderlineStyleDouble) the font of cell A11 (Range(“A11”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook).
Sub fontUnderline() 'Source: https://powerspreadsheets.com/ 'underlines the font 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'underline the font ThisWorkbook.Worksheets("VBA Font").Range("A11").font.Underline = xlUnderlineStyleDouble End Sub
Effects of executing macro example to set font underline
The following GIF illustrates the results of executing the macro example. As expected, Excel underlines the font of cell A11 with a double line.
#8: Set font strikethrough
VBA code to set font strikethrough
To strike the font through, use a statement with the following structure:
Range.Font.Strikethrough = True
Process to set font strikethrough
To strike the font through, follow these steps:
- Identify the cell range whose font you strike through (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Strikethrough property to True (Font.Strikethrough = True).
VBA statement explanation
Item: Range
Range object representing the cell range whose font you strike through.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Strikethrough
The Font.Strikethrough property strikes through (or not) the font with a horizontal line.
Item: =
The assignment operator assigns a new value (True) to the Font.Strikethrough property.
Item: True
To strike through the font with a horizontal line, set the Font.Strikethrough property to True.
To remove a font's strike through horizontal line, set the Font.Strikethrough property to False.
Macro example to set font strikethrough
The following macro example strikes through (font.Strikethrough = True) the font of cell A12 (Range(“A12”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook).
Sub fontStrikethrough() 'Source: https://powerspreadsheets.com/ 'strikes font through 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'strike through font ThisWorkbook.Worksheets("VBA Font").Range("A12").font.Strikethrough = True End Sub
Effects of executing macro example to set font strikethrough
The following GIF illustrates the results of executing the macro example. As expected, Excel strikes the font of cell A12 through.
#9: Change or set font color with RGB color model
VBA code to change or set font color with RGB color model
To change or set the font color with the RGB color model, use a statement with the following structure:
Range.Font.Color = RGB(Red, Green, Blue)
Process to change or set font color with RGB color model
To change or set the font color with the RGB color model, follow these steps:
- Identify the cell range whose font color you change with the RGB color model (Range).
- Refer to the Font object representing Range's font (Font).
- Specify the red, green and blue components of the color with the RGB function (RGB(Red, Green, Blue)).
- Set the Font.Color property to the value returned by the RGB Function (Font.Color = RGB(Red, Green, Blue)).
VBA statement explanation
Item: Range
Range object representing the cell range whose font color you change with the RGB color model.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Color
The Font.Color property sets the font color using a numeric value.
Item: =
The assignment operator assigns a new value (returned by the RGB function) to the Font.Color property.
Item: RGB(Red, Green, Blue)
Theoretically, you can set the Font.Color property to a value specifying the font color you use.
In practice, you can use the RGB function to obtain the value specifying the font color. For these purposes, specify the Red, Green and Blue components of the color.
When working with the RGB function, consider the following:
- Specify each component (Red, Green and Blue) as numbers between 0 and 255 (inclusive).
- If you use a value exceeding 255, VBA assumes that the value is 255.
Macro example to change or set font color with RGB color model
The following macro example sets the font color of cell A13 (Range(“A13”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to red with the RGB color model (font.Color = RGB(255, 0, 0)).
Sub fontColorRgb() 'Source: https://powerspreadsheets.com/ 'sets font color using RGB color model 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify font color with RGB function ThisWorkbook.Worksheets("VBA Font").Range("A13").font.Color = RGB(255, 0, 0) End Sub
Effects of executing macro example to change or set font color with RGB color model
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font color of cell A13 to red with the RGB color model.
#10: Change or set font color with color index (ColorIndex)
VBA code to change or set font color with color index (ColorIndex)
To change or set the font color with the ColorIndex property, use a statement with the following structure:
Range.Font.ColorIndex = ColorIndex#
Process to change or set font color with color index (ColorIndex)
To change or set the font color with the ColorIndex property, follow these steps:
- Identify the cell range whose font color you change with the ColorIndex property (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.ColorIndex property to a value between 0 and 56 or an xlColorIndex constant (Font.ColorIndex = ColorIndex#).
VBA statement explanation
Item: Range
Range object representing the cell range whose font color you change with the ColorIndex property.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: ColorIndex
The Font.ColorIndex property sets the font color using the current color palette or a constant from the xlColorIndex enumeration.
Item: =
The assignment operator assigns a new value (ColorIndex#) to the Font.ColorIndex property.
Item: ColorIndex#
Set the Font.ColorIndex to one of the following:
- A value between 0 and 56, representing a color from the current color palette.
- One of the following xlColorIndex constants:
- xlColorIndexAutomatic (-4105), which represents automatic color.
- xlColorIndexNone (-4142), which represents no color.
Macro example to change or set font color with color index (ColorIndex)
The following macro example sets the font color of cell A14 (Range(“A14”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to blue with the ColorIndex property (font.ColorIndex = 5).
Sub fontColorIndex() 'Source: https://powerspreadsheets.com/ 'sets the font color by referring to the current color palette or a constant 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify font color as index value of the current color palette or an XlColorIndex constant ThisWorkbook.Worksheets("VBA Font").Range("A14").font.ColorIndex = 5 End Sub
Effects of executing macro example to change or set font color with color index (ColorIndex)
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font color of cell A14 to blue with the ColorIndex property.
#11: Set font color to Automatic
VBA code to set font color to Automatic
To set the font color to Automatic (within the color palette), use a statement with the following structure:
Range.Font.ColorIndex = xlColorIndexAutomatic
Process to set font color to Automatic
To set the font color to Automatic (within the color palette), follow these steps:
- Identify the cell range whose font color you set to Automatic (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.ColorIndex property to xlColorIndexAutomatic (Font.ColorIndex = xlColorIndexAutomatic).
VBA statement explanation
Item: Range
Range object representing the cell range whose font color you set to Automatic (within the color palette).
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: ColorIndex
The Font.ColorIndex property sets the font color using the current color palette or a constant from the xlColorIndex enumeration.
Item: =
The assignment operator assigns a new value (xlColorIndexAutomatic) to the Font.ColorIndex property.
Item: xlColorIndexAutomatic
To set the font color to Automatic, set the Font.ColorIndex to:
- xlColorIndexAutomatic (-4105); or
- 0.
Macro example to set font color to Automatic
The following macro example sets the font color of cell A15 (Range(“A15”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to Automatic (font.ColorIndex = xlColorIndexAutomatic).
Sub fontColorAutomatic() 'Source: https://powerspreadsheets.com/ 'sets the font color to automatic 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the font color as Automatic ThisWorkbook.Worksheets("VBA Font").Range("A15").font.ColorIndex = xlColorIndexAutomatic End Sub
Effects of executing macro example to set font color to Automatic
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font color of cell A15 to Automatic (from blue).
#12: Change or set font color with theme color scheme (ThemeColor, xlThemeColorAccent)
VBA code to change or set font color with theme color scheme (ThemeColor, xlThemeColorAccent)
To change or set the font color with the theme color scheme, use a statement with the following structure:
Range.Font.ThemeColor = xlThemeColorConstant
Process to change or set font color with theme color scheme (ThemeColor, xlThemeColorAccent)
To change or set the font color with the theme color scheme, follow these steps:
- Identify the cell range whose font color you change with the theme color scheme (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.ThemeColor property to an xlThemeColor constant (Font.ThemeColor = xlThemeColorConstant).
VBA statement explanation
Item: Range
Range object representing the cell range whose font color you change with the theme color scheme.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: ThemeColor
The Font.ThemeColor property sets the font color using the theme color scheme.
Item: =
The assignment operator assigns a new value (xlThemeColorConstant) to the Font.ThemeColor property.
Item: xlThemeColorConstant
The constants in the xlThemeColor enumeration specify the theme color. Therefore, set the Font.ThemeColor property to one of the following xlThemeColor constants:
xlThemeColor constant | Value | Description |
xlThemeColorAccent1 | 5 | Accent 1. |
xlThemeColorAccent2 | 6 | Accent 2. |
xlThemeColorAccent3 | 7 | Accent 3. |
xlThemeColorAccent4 | 8 | Accent 4. |
xlThemeColorAccent5 | 9 | Accent 5. |
xlThemeColorAccent6 | 10 | Accent 6. |
xlThemeColorDark1 | 1 | Dark 1. |
xlThemeColorDark2 | 3 | Dark 2. |
xlThemeColorFollowedHyperlink | 12 | Followed hyperlink. |
xlThemeColorHyperlink | 11 | Hyperlink. |
xlThemeColorLight1 | 2 | Light 1. |
xlThemeColorLight2 | 4 | Light 2. |
Macro example to change or set font color with theme color scheme (ThemeColor, xlThemeColorAccent)
The following macro example sets the font color of cell A16 (Range(“A16”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) to the accent 1 of the theme color (font.ThemeColor = xlThemeColorAccent1).
Sub fontThemeColor() 'Source: https://powerspreadsheets.com/ 'sets font color by referring to applicable theme colors 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'specify the font color from the theme color scheme ThisWorkbook.Worksheets("VBA Font").Range("A16").font.ThemeColor = xlThemeColorAccent1 End Sub
Effects of executing macro example to change or set font color with theme color scheme (ThemeColor, xlThemeColorAccent)
The following GIF illustrates the results of executing the macro example. As expected, Excel sets the font color of cell A16 to the accent 1 of the theme color.
#13: Change or set font tint and shade
VBA code to change or set font tint and shade
To change or set the font tint and shade, use a statement with the following structure:
Range.Font.TintAndShade = TintAndShade#
Process to change or set font tint and shade
To change or set the font tint and shade, follow these steps:
- Identify the cell range whose font tint and shade you change (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.TintAndShade property to a value (Font.TintAndShade = TintAndShade#) between -1 (darkest shade) and 1 (lightest shade).
VBA statement explanation
Item: Range
Range object representing the cell range whose font tint and shade you change.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: TintAndShade
The Font.TintAndShade property lightens or darkens the font color.
Item: =
The assignment operator assigns a new value (TintAndShade#) to the Font.TintAndShade property.
Item: TintAndShade#
Set the Font.TintAndShade property to a value between -1 (darkest shade) and 1 (lightest shade). If you attempt to set the Font.TintAndShade property to a value outside this range, a run-time error (5: Invalid procedure call or argument) occurs.
Macro example to change or set font tint and shade
The following macro example lightens the font (font.TintAndShade = 0.5) of cell A17 (Range(“A17”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook).
Sub fontTintAndShade() 'Source: https://powerspreadsheets.com/ 'lightens or darkens the font color 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'lighten or darken the font color ThisWorkbook.Worksheets("VBA Font").Range("A17").font.TintAndShade = 0.5 End Sub
Effects of executing macro example to change or set font tint and shade
The following GIF illustrates the results of executing the macro example. As expected, Excel lightens the font color of cell A17.
#14: Set font subscript
VBA code to set font subscript
To format the font as subscript, use a statement with the following structure:
Range.Font.Subscript = True
Process to set font subscript
To format the font as subscript, follow these steps:
- Identify the cell range whose font you format as subscript (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Subscript property to True (Font.Subscript = True).
VBA statement explanation
Item: Range
Range object representing the cell range whose font you format as subscript.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Subscript
The Font.Subscript property formats the font as subscript (or not).
Item: =
The assignment operator assigns a new value (True) to the Font.Subscript property.
Item: True
To format the font as subscript, set the Font.Subscript property to True.
To remove the font's subscript formatting, set the Font.Subscript property to False.
Macro example to set font subscript
The following macro example formats the font of cell A18 (Range(“A18”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) as subscript (font.Subscript = True).
Sub fontSubscript() 'Source: https://powerspreadsheets.com/ 'formats the font as a subscript 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'format the font as subscript ThisWorkbook.Worksheets("VBA Font").Range("A18").font.Subscript = True End Sub
Effects of executing macro example to set font subscript
The following GIF illustrates the results of executing the macro example. As expected, Excel formats the font of cell A18 as subscript.
#15: Set font superscript
VBA code to set font superscript
To format the font as superscript, use a statement with the following structure:
Range.Font.Superscript = True
Process to set font superscript
To format the font as superscript, follow these steps:
- Identify the cell range whose font you format as superscript (Range).
- Refer to the Font object representing Range's font (Font).
- Set the Font.Superscript property to True (Font.Superscript = True).
VBA statement explanation
Item: Range
Range object representing the cell range whose font you format as superscript.
You can usually work with, among others, the following properties to refer to this Range object:
- Worksheet.Range.
- Worksheet.Cells.
Item: Font
The Range.Font property returns a Font object representing Range's font.
Item: Superscript
The Font.Superscript property formats the font as superscript (or not).
Item: =
The assignment operator assigns a new value (True) to the Font.SuperScript property.
Item: True
To format the font as superscript, set the Font.Superscript to True.
To remove the font's superscript formatting, set the Font.Superscript to False.
Macro example to set font superscript
The following macro example formats the font of cell A19 (Range(“A19”)) of the “VBA Font” worksheet (Worksheets(“VBA Font”)) in the workbook where the macro is stored (ThisWorkbook) as superscript (font.Superscript = True).
Sub fontSuperscript() 'Source: https://powerspreadsheets.com/ 'formats the font as a superscript 'For further information: https://powerspreadsheets.com/excel-vba-font/ 'format the font as superscript ThisWorkbook.Worksheets("VBA Font").Range("A19").font.Superscript = True End Sub
Effects of executing macro example to set font superscript
The following GIF illustrates the results of executing the macro example. As expected, Excel formats the font of cell A19 as superscript.
Learn more about specifying font characteristics with VBA
Workbook examples used in this VBA Font Tutorial
You can get immediate free access to the example workbooks that accompany this VBA Font Tutorial by subscribing to the Power Spreadsheets Newsletter.
References to constructs used in this VBA Font Tutorial
Use the following links to visit the appropriate webpage in the Microsoft Developer Network:
- Refer to the workbook containing the cell range you work with:
- Refer to the worksheet containing the cell range you work with:
- Refer to the cell range you work with:
- Refer to a cell range's font:
- Set or change a font's properties:
- Font.Bold property.
- Font.Color property.
- Font.ColorIndex property and xlColorIndex enumeration.
- Font.FontStyle property.
- Font.Italic property.
- Font.Name property.
- Font.Size property.
- Font.Strikethrough property.
- Font.Subscript property.
- Font.Superscript property.
- Font.ThemeColor property and xlThemeColor enumeration.
- Font.ThemeFont property and xlThemeFont enumeration.
- Font.TintAndShade property.
- Font.Underline property and xlUnderlineStyle enumeration.
- Assign a new value to a property:
- Obtain a color with the RGB color model:
- Work with variables and data types: