Excel Macro Generator
Create an Excel macro without writing VBA by hand. Pick a template, customize the sheet names and ranges, and copy ready-to-paste code - free, no signup, nothing uploaded.
1. Pick a Macro Template
2. Customize: Format All Cells
Apply a consistent font and autofit every column on a sheet.
3. Copy Your VBA Code
Sub FormatAllCells()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws.Cells.Font
.Name = "Calibri"
.Size = 11
End With
ws.Cells.WrapText = False
ws.Columns.AutoFit
End SubWhat This Macro Does
Sets the font of every cell on the "Sheet1" sheet to Calibri size 11, turns off text wrapping, and autofits all column widths so nothing is cut off. Handy for making a raw data dump presentable in one click.
How to Add the Macro in Excel
- 1Show the Developer tab
Go to File > Options > Customize Ribbon and check Developer, then click OK. (On Mac: Excel > Preferences > Ribbon & Toolbar.)
- 2Open the Visual Basic editor
Click Visual Basic on the Developer tab, or press Alt+F11 (Option+F11 on Mac).
- 3Insert a module
In the VBA editor menu, choose Insert > Module. A blank code window appears.
- 4Paste the macro
Copy the generated VBA code above and paste it into the module window.
- 5Run it and save as .xlsm
Press F5 in the editor, or run it from Developer > Macros. Save the workbook as a macro-enabled .xlsm file to keep the macro.
Macros only run in desktop Excel, and the workbook must be saved as a macro-enabled .xlsm file - a standard .xlsx cannot store VBA.
About This Excel Macro Generator
VBA (Visual Basic for Applications) is the programming language built into Excel, and macros are how you automate repetitive spreadsheet work - formatting reports, sorting exports, cleaning empty rows, building pivot tables. The catch is that most people who would benefit from a macro don't want to learn VBA syntax first. This free Excel macro generator bridges that gap: choose one of the nine ready-made templates, fill in plain-English inputs like the sheet name, column, and range, and the tool writes correct, commented VBA you can paste straight into Excel.
Macro Templates Included
- Format all cells - apply a consistent font and autofit every column in one click.
- Sort data - sort a range by any column, ascending or descending, with the header row preserved.
- Filter and copy - filter rows by a criterion and copy the matches to another sheet.
- Loop through rows - iterate every row until an empty cell, a skeleton for your own per-row logic.
- Send email from Excel - create and send an Outlook email directly from a macro.
- Create pivot table - build a pivot table from a data range with your chosen row and value fields.
- Merge cells - merge a range into one centered cell without the warning popup.
- Delete empty rows - remove every row whose key column is blank, iterating bottom-up so indexes stay valid.
- Copy to another sheet - copy a range with formulas and formatting to a different sheet.
Why Generate VBA Instead of Writing It?
Even experienced Excel users trip over VBA's quirks: worksheet references that break when a sheet is renamed, sort keys that swallow the header row, loops that skip rows after a deletion. Each template here encodes the safe pattern - bottom-up row deletion, header-aware sorts, alert suppression around merges - so the code works the first time. And because every input is substituted into the code before you copy it, there are no placeholders left to hunt down and replace.
Keeping Your Macros
Excel stores VBA only in macro-enabled files, so after pasting your code save the workbook with the .xlsm extension. If you later need to share the data without the code, our Excel Macro Remover strips the VBA project and leaves a clean .xlsx copy.