Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created March 17, 2026 16:52
Show Gist options
  • Select an option

  • Save chadbrewbaker/e4612602eaad74f20d97cc294aed2e51 to your computer and use it in GitHub Desktop.

Select an option

Save chadbrewbaker/e4612602eaad74f20d97cc294aed2e51 to your computer and use it in GitHub Desktop.
fix tabular data
Sub FixTabularData()
Dim rng As Range
Dim cell As Range
' Only act on the selected cells
Set rng = Selection
On Error Resume Next
' Optimization: Only process cells that contain numbers
' This prevents the macro from ruining your text headers
Dim numericCells As Range
Set numericCells = rng.SpecialCells(xlCellTypeConstants, xlNumbers)
If numericCells Is Nothing Then
MsgBox "No numeric constants found in selection.", vbExclamation
Exit Sub
End If
On Error GoTo 0
With numericCells
' 1. Fix Decimal Places (Setting to 2 by default)
' Use "#,##0.00" for thousands separator and 2 fixed decimals
.NumberFormat = "#,##0.00"
' 2. Fix Alignment (Right Aligned)
.HorizontalAlignment = xlRight
' 3. Fix Font (Monospaced digits)
' Consolas or Courier New are standard monospaced fonts
.Font.Name = "Consolas"
.Font.Size = 10 ' Adjust size as preferred
End With
MsgBox "Data alignment corrected: Fixed decimals, right-aligned, and monospaced digits applied.", vbInformation
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment