Format Cells with VBA: Fonts, Colours, Borders and Number Formats

Format Cells with VBA: Fonts, Colours, Borders and Number Formats

📎 This article includes 1 downloadable practice file ↓

⏱ 4 min read

Reports get judged by how they look before anyone reads a number. Formatting by hand every month is exactly the kind of job macros are for. This lesson covers the formatting you’ll use in real reports and how to apply it quickly to whole ranges.

In this article
  1. Fonts
  2. Fill colour
  3. Borders
  4. Number formats (including Indian style)
  5. Alignment, wrap and widths
  6. Banded rows quickly
  7. Conditional formatting from VBA
  8. A complete report formatter
  9. Where people go wrong
  10. Practice
  11. Continue learning

Fonts

With ws.Range("A1")
    .Value = "Monthly Sales Report"
    .Font.Name = "Calibri"
    .Font.Size = 16
    .Font.Bold = True
    .Font.Color = RGB(196, 83, 31)
End With
ws.Range("A3:F3").Font.Bold = True          ' header row

Fill colour

ws.Range("A3:F3").Interior.Color = RGB(33, 115, 70)     ' Excel green
ws.Range("A3:F3").Font.Color = vbWhite
ws.Range("A4:F100").Interior.Pattern = xlNone             ' clear fills
💡 Get exact colours from Excel: Home › Fill Color › More Colors › Custom shows the RGB numbers of any colour you pick.

Borders

With ws.Range("A3").CurrentRegion.Borders
    .LineStyle = xlContinuous
    .Weight = xlThin
    .Color = RGB(200, 200, 200)
End With
ws.Range("A3:F3").Borders(xlEdgeBottom).Weight = xlMedium

Number formats (including Indian style)

Format code Shows
"#,##0" 1,234,567
"[>=10000000]##\,##\,##\,##0;[>=100000]##\,##\,##0;##,##0" 12,34,567 (lakh/crore grouping)
"₹ #,##0.00" ₹ 1,250.00
"0.0%" 18.0%
"dd-mmm-yyyy" 05-Oct-2026
"#,##0;[Red]-#,##0" negative numbers in red
ws.Range("E4:E100").NumberFormat = "₹ #,##0.00"
ws.Range("D4:D100").NumberFormat = "dd-mmm-yyyy"
⚠️ Number formats change how a value looks, not the value. A cell showing “1,250” may hold 1249.6 — round with Round() if the stored value must match.

Alignment, wrap and widths

With ws.Range("A3:F3")
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = True
End With
ws.Columns("A:F").AutoFit
ws.Columns("B").ColumnWidth = 28
ws.Rows(3).RowHeight = 30

Banded rows quickly

Dim r As Long
For r = 4 To lastRow Step 2
    ws.Range(ws.Cells(r, 1), ws.Cells(r, 6)).Interior.Color = RGB(245, 248, 245)
Next r

Even simpler: turn the data into a Table, which bands rows automatically.

Advertisement
Dim lo As ListObject
Set lo = ws.ListObjects.Add(xlSrcRange, ws.Range("A3").CurrentRegion, , xlYes)
lo.Name = "tblSales": lo.TableStyle = "TableStyleMedium2"

Conditional formatting from VBA

With ws.Range("E4:E100").FormatConditions.Add(Type:=xlCellValue, Operator:=xlGreater, Formula1:="=100000")
    .Interior.Color = RGB(255, 235, 156)
    .Font.Bold = True
End With
ws.Range("E4:E100").FormatConditions.AddDatabar

Conditional formats update on their own when values change, unlike colours a macro paints once.

A complete report formatter

Sub FormatReport()
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Report")
    Dim rng As Range: Set rng = ws.Range("A3").CurrentRegion
    Application.ScreenUpdating = False
    rng.Font.Name = "Calibri": rng.Font.Size = 11
    With rng.Rows(1)
        .Font.Bold = True: .Interior.Color = RGB(33, 115, 70): .Font.Color = vbWhite
        .HorizontalAlignment = xlCenter
    End With
    rng.Borders.LineStyle = xlContinuous: rng.Borders.Color = RGB(210, 210, 210)
    rng.Columns(5).NumberFormat = "₹ #,##0.00"
    rng.Columns(4).NumberFormat = "dd-mmm-yyyy"
    rng.Columns.AutoFit
    ws.Activate: ws.Range("A4").Select: ActiveWindow.FreezePanes = True
    Application.ScreenUpdating = True
End Sub

Where people go wrong

  • Slow formatting loops — format the whole range at once instead of cell by cell.
  • Colours look different — ColorIndex depends on the workbook palette; RGB() is exact.
  • ₹ shows as ? — the VBA editor can’t store some symbols in code; use ChrW(8377) to build the format string.

Practice

The workbook has an unformatted report and buttons that format it step by step, so you can see what each block of code does. Try changing the colours to your company’s.

Next: decisions — If, ElseIf, And/Or and Select Case.

⚡ Interactive Practice Lab & Formula Tester:

Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.

📎 Practice files for this article

  • 📗
    Practice workbook with all course macros (.xlsm)Open it, click Enable Content in the yellow bar, go to the Macros sheet and press any button. 60 sales rows included to test on.
    ⬇ XLSM · 29 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

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