Skip to content

Excel VBA Formatting Cells and Values

    Change Font size

    ActiveCell.Font.Size = 14

    Embolden font

    Selection.Font.Bold = True

    Italicise font

    Selection.Font.Italic = True

    Underline font

    Selection.Font.Underline = True

    Font colour

    Selection.Font.Color = vbRed

    Also: vbBlack, vbBlue, vbCyan, vbGreen, vbMagenta, vbWhite,vbYellow

    Selection.Font.Color = rgbBlueViolet

    NB. Use CTRL SPACE to show the intellisense list of rgb colours

    Selection.Font.Color = RGB(10, 201, 88)
    ActiveCell.Font.ThemeColor = xlThemeColorAccent2
    Selection.Font.ColorIndex = 49

    This table shows the index number for colours in the default colour palette.

    Background Colour of Cell/s

    See font colour above for different ways of specifying colour.

    Selection.Interior.Color = vbRed

    Cell Borders

    See font colour above for different ways of specifying colour.

    Selection.Borders.Color = vbBlue

    You can also specify properties such as weight and line style

    With Selection.Borders
       .Color = vbBlue
       .Weight = xlMedium
       .LineStyle = xlDash
    End With

    Cell Alignment

    Selection.HorizontalAlignment = xlCenter
    Selection.VerticalAlignment = xlTop

    To merge and center

    Range("A1:E1").Merge
    Range("A1").HorizontalAlignment = xlCenter

    Formatting Values

    Number Format

    ActiveCell.NumberFormat = "£#,##0.00;[Red]-£#,##0.00"
    ActiveCell.NumberFormat = "0%"
    ActiveCell.NumberFormat = "dd/mm/yyyy"

    Use the custom format codes available in Excel’s Format | Cells dialog box.