How to Set Font Size Using VBA (With Example)


You can use the Font.Size property in VBA to get and set the font size of specific cells in Excel.

For example, you could use the following macro to create a message box that displays the current font size of cell A1:

Sub GetFontSize()
MsgBox Range("A1").Font.Size
End Sub

Or you could create the following macro to set the font size of cell A1 to be 20:

Sub SetFontSize()
Range("A1").Font.Size = 20
End Sub

Or you could create the following macro to make the font size in each cell in the range A1:C1 to be 20:

Sub SetFontSize()
Range("A1:C1").Font.Size = 20
End Sub

The following examples show how to get and set font size using VBA with the following dataset in Excel:

Example 1: Get Font Size Using VBA

We can create the following macro to create a message box that displays the current font size of cell A1:

Sub GetFontSize()
MsgBox Range("A1").Font.Size
End Sub

When we run this macro, we receive the following output:

The message box tells us that cell A1 currently has a font size of 11.

This is the default font size in Excel.

Example 2: Set Font Size of Specific Cell Using VBA

We can create the following macro to set the font size of cell A1 to be 20:

Sub SetFontSize()
Range("A1").Font.Size = 20
End Sub

When we run this macro, we receive the following output:

We can see that the font size of cell A1 has been changed to 20 while the font size of all other cells has remained unchanged.

Example 3: Set Font Size of Range of Cells Using VBA

We can create the following macro to set the font size of each cell in the range A1:C1 to be 20:

Sub SetFontSize()
Range("A1:C1").Font.Size = 20
End Sub

When we run this macro, we receive the following output:

We can see that the font size of each cell in the range A1:C1 has been changed to 20 while the font size of all other cells has remained unchanged.

Note: You can find the complete documentation for the VBA Font.Size property here.

Additional Resources

The following tutorials explain how to perform other common tasks in VBA:

VBA: How to Change Font Color
VBA: How to Make Font Bold
VBA: How to Replace Characters in String

Leave a Reply

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