Return to VBA Code Examples

VBA Cell Font – Modify Color, Size, Mode, & More than

In this Commodity

  • VBA Prison cell Font
  • Change Font Colour
    • vbColor
    • Color – RGB
    • ColorIndex
  • Font Size
  • Bold Font
  • Font Name
  • Cell Way

VBA Cell Font

In VBA, y'all can change font properties using the VBA Font Property of the Range Object. Blazon the following code into the VBA Editor and you'll run into a list of all the options bachelor:

vba cell font

Nosotros will discuss a few of the almost common properties below.

Modify Font Color

At that place are a few ways to gear up font colors.

vbColor

The easiest way to set colors is with vbColors:

Nevertheless, you're very limited in terms of colors available. These are the only options available:

vba vbcolor

Color – RGB

Y'all can too set colors based on RGB (Red Dark-green Blue). Here yous enter color values between 0-255 for Cherry-red, Green, and Blue. Using those three colors you tin can brand whatever color:

ColorIndex

VBA / Excel also has a ColorIndex property. This makes pre-built colors bachelor to you. However, they're stored as Index numbers, which makes it hard to know what color is what:

We wrote an article about VBA Color codes, including a list of the VBA ColorIndex codes. In that location you tin can acquire more than about colors.

Font Size

This will set the font size to 12:

or to 16:

VBA Coding Made Easy

Finish searching for VBA lawmaking online. Larn more than about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding noesis and with many time-saving features for all users! automacro

Learn More!!

Assuming Font

Information technology is easy to set a cell font to Bold:

or to clear Assuming formatting:

Font Proper name

To change a font proper name use the Name property:

Prison cell Style

Excel offers the ability to create Cell "Styles". Styles can exist found in the Abode Ribbon > Styles:

excel vba font styles

Styles allow you to relieve your desired Jail cell Formatting. Then assign that manner to a new cell and all of the cell formatting is instantly applied.  Including Font size, cell colour, cell protections status, and anything else available from the Cell Formatting Carte du jour:

cell formatting menu excel

Personally, for many of the models that I piece of work on, I ordinarily create an "Input" jail cell style:

By using styles you tin also hands identify cell types on your worksheet.  The case below will loop through all the cells in the worksheet and change whatsoever cell with Style = "Input" to "InputLocked":