Data Tools · VBA

Auto-Format & Clean Sheet

Bold the header, trim text and autofit every column.

download.bas (ES) download.bas (EN)
' Cleans the active sheet: bold header, trim text, autofit columns, freeze the header row.
Sub CleanAndFormatSheet()
    Dim ws As Worksheet, c As Range
    Set ws = ActiveSheet
    Application.ScreenUpdating = False

    With ws.Rows(1)
        .Font.Bold = True
        .Interior.Color = RGB(21, 101, 192)
        .Font.Color = vbWhite
    End With

    For Each c In ws.UsedRange.Cells
        If VarType(c.Value) = vbString Then c.Value = Trim(c.Value)
    Next c

    ws.UsedRange.Columns.AutoFit
    ws.Range("A2").Select
    ActiveWindow.FreezePanes = True
    Application.ScreenUpdating = True
End Sub

Free to use and modify · ExcelBot — excelempowers.com

Formats the header row, trims stray spaces from text cells, autofits columns and freezes the header.

How to install:

  1. Open your workbook and press Alt + F11 to open the VBA editor.
  2. Choose Insert ▸ Module and paste the code (or File ▸ Import File for the .bas).
  3. Press F5 to run, or run it from Developer ▸ Macros.
  4. Save your file as .xlsm (macro-enabled) to keep the macro.

No VBA? In ExcelBot you can do the same thing by just asking the AI in plain language.

format clean autofit trim formato limpieza
Rather not use VBA?

In ExcelBot you get the same result by asking the AI in plain language — no macros needed.

Try ExcelBot free Browse more macros

Related macros