Excel macros for beginners start with three steps: turn on the Developer tab, save your workbook as .xlsm, and paste short VBA code into a module. This guide gives you seven business macros, from bulk folder creation to PDF export and Outlook events, each with numbered steps and code you can read line by line.
Last updated: November 2026
Key takeaways
- A macro is a saved set of VBA instructions. Once it works, one button click replaces minutes or hours of repeated clicking.
- Macros only survive in .xlsm files. Save as .xlsx and Excel strips the code without a second warning.
- Every code block in this post starts with Option Explicit, so a mistyped variable name stops the macro instead of silently giving wrong numbers.
- The seven tasks cover folders, splitting data, PDF export, Outlook events, text cleanup, a change log and form reset.
- If you would rather not write code, the Excel VBA Tools & Utilities Pack has 8 finished VBA applications for $63.99 against $105.92 bought one by one.
Launch offerRecord, read and write your own Excel macros and UserForms, and use AI assistants as your VBA tutor without trusting them blindly. 6h 12m of video by PK, with practice files and a capstone.
What are Excel macros for beginners, and what can they do?
A macro is a small program written in VBA (Visual Basic for Applications), the language built into Microsoft Excel on Windows. It can click, copy, format, save and send for you, in the same order every time and without typos.
The test for a good first macro is simple. If you do the same sequence of clicks more than twice a week, and the result is always the same, it is a candidate. Renaming files, splitting a customer list by region and saving a report as PDF all pass that test.
Macros are not formulas. A formula returns a value in a cell. A macro performs actions: it creates sheets, writes into cells, opens other programs and saves files. That is why they suit back-office routines that formulas cannot touch.
How do I enable the Developer tab and save as .xlsm?
Do this once per computer. It takes about two minutes, and every later section assumes you have done it.
- Open Excel and choose File, then Options, then Customize Ribbon.
- In the right-hand list of main tabs, tick Developer and press OK. The tab now appears on the ribbon.
- Open File, Options, Trust Center, Trust Center Settings, Macro Settings. Choose Disable VBA macros with notification (older versions call it Disable all macros with notification). This lets your own files ask permission and keeps unknown files blocked.
- Create a new workbook, press F12 (Save As), and set Save as type to Excel Macro-Enabled Workbook (*.xlsm).
- Press Alt + F11 to open the Visual Basic Editor. In the menu choose Insert, then Module. A blank white window opens. That is where the code in this post goes.
To run a macro, click inside its Sub, press F5, or use Developer, Macros, select the name and press Run. To put it behind a button, use Developer, Insert, Button (Form Control), draw the button and pick the macro when prompted.
Microsoft publishes its own walkthrough of recording a first macro in the Microsoft Support quick start for creating a macro. Recording is a fine way to see how Excel describes your clicks, but recorded code is long and brittle. The hand-written examples below are shorter and easier to fix.
Which 7 business tasks should I automate first?
The seven tasks below are ordered from the most mechanical to the most flexible. Each has numbered steps, a code block and a shortcut box that names one ready-made NGT tool if you want the finished version.
| Task | Main VBA idea | Ready-made shortcut | Price |
|---|---|---|---|
| 1. Create folders from a list | MkDir inside a loop | Folder Automation Tool V1.0 | $6.99 |
| 2. Split data into one sheet per category | Copy rows to named sheets | Data Segregation Tool | $6.99 |
| 3. Save a sheet as PDF | ExportAsFixedFormat | Automation: Excel to PDF Converter | $6.99 |
| 4. Create Outlook calendar events | CreateObject(“Outlook.Application”) | Outlook Calendar Events Automation | $4.99 |
| 5. Clean messy text | Trim and Replace over a selection | Excel VBA Tools & Utilities Pack | $63.99 |
| 6. Keep a change log | Write Now and user name to a sheet | Excel VBA Tools & Utilities Pack | $63.99 |
| 7. Reset a form | ClearContents on set ranges | Excel VBA Tools & Utilities Pack | $63.99 |
How do I create folders in bulk with a macro?
Project managers and admins build the same folder trees again and again: one folder per client, one per month, one per job number. Typing them in Windows Explorer is slow and invites spelling differences.
- Rename a sheet to Folders. Type a base path such as C:\Projects in cell B1 (label it in A1).
- List the new folder names in column A, starting at A3.
- Paste the code below into a module and run it.
- Column B reports Created or Already exists for each row.
Option Explicit
Sub CreateFolders()
Dim ws As Worksheet
Dim basePath As String
Dim lastRow As Long
Dim r As Long
Dim fullPath As String
Set ws = ThisWorkbook.Worksheets("Folders")
basePath = ws.Range("B1").Value
If Right(basePath, 1) <> Application.PathSeparator Then
basePath = basePath & Application.PathSeparator
End If
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For r = 3 To lastRow
If Len(ws.Cells(r, "A").Value) > 0 Then
fullPath = basePath & ws.Cells(r, "A").Value
If Dir(fullPath, vbDirectory) = "" Then
MkDir fullPath
ws.Cells(r, "B").Value = "Created"
Else
ws.Cells(r, "B").Value = "Already exists"
End If
End If
Next r
End SubHow it works: the loop walks down column A, joins each name to the base path, and asks Dir whether that folder exists. Only missing folders are made. MkDir creates one level at a time, so the base path itself must already exist.
Worked example: with C:\Projects in B1 and the names Acme Ltd, Birch & Co and Cedar Group in A3:A5, three folders appear under C:\Projects and column B shows Created three times. Run it again and all three rows say Already exists.
How do I split one table into a sheet per category?
A sales export with a Region column is a classic case. Sending each regional manager only their rows means filtering, copying and pasting into a new sheet, four or five times a month.
- Name the sheet holding your table Data. Put headers in row 1.
- Make sure the category is in column C (change the 3 in the code if yours is elsewhere).
- Run the macro. A new sheet appears for each distinct category, with the header row copied over.
- Delete those sheets before running again, otherwise rows are appended a second time.
Option Explicit
Sub SplitByCategory()
Dim src As Worksheet
Dim dest As Worksheet
Dim lastRow As Long
Dim lastCol As Long
Dim r As Long
Dim cat As String
Dim nextRow As Long
Set src = ThisWorkbook.Worksheets("Data")
lastRow = src.Cells(src.Rows.Count, "A").End(xlUp).Row
lastCol = src.Cells(1, src.Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False
For r = 2 To lastRow
cat = Left(Trim(CStr(src.Cells(r, 3).Value)), 31)
If Len(cat) > 0 Then
Set dest = Nothing
On Error Resume Next
Set dest = ThisWorkbook.Worksheets(cat)
On Error GoTo 0
If dest Is Nothing Then
Set dest = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
dest.Name = cat
src.Range(src.Cells(1, 1), src.Cells(1, lastCol)).Copy dest.Cells(1, 1)
End If
nextRow = dest.Cells(dest.Rows.Count, "A").End(xlUp).Row + 1
src.Range(src.Cells(r, 1), src.Cells(r, lastCol)).Copy dest.Cells(nextRow, 1)
End If
Next r
Application.CutCopyMode = False
Application.ScreenUpdating = True
End SubTwo details matter here. Excel sheet names are limited to 31 characters and cannot contain characters such as / \ ? * : [ ], which is why the code trims to 31. And turning ScreenUpdating off makes the macro run noticeably faster on thousands of rows, but you must turn it back on, or Excel looks frozen after an error.
How do I save a sheet as a PDF with one click?
Invoices, monthly reports and price lists all end up as PDFs. File, Save As, pick PDF, choose a folder, type a name: six steps that a macro reduces to one.
- Open the workbook that holds the sheet you want to send.
- Set the print area and page orientation once under Page Layout. The macro uses those settings.
- Paste the code below, then save the workbook so ThisWorkbook.Path is known.
- Run the macro with the sheet active. A PDF named after the sheet and today’s date lands beside the workbook.
Option Explicit
Sub SaveSheetAsPDF()
Dim ws As Worksheet
Dim filePath As String
Set ws = ActiveSheet
filePath = ThisWorkbook.Path & Application.PathSeparator & ws.Name & "_" & Format(Date, "yyyy-mm-dd") & ".pdf"
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath, Quality:=xlQualityStandard, OpenAfterPublish:=False
MsgBox "Saved: " & filePath
End SubThe date stamp stops one day’s file overwriting another. If you want the whole workbook in one PDF, replace ws with ThisWorkbook; the method works on both objects.
How do I create Outlook calendar events from Excel rows?
Training schedules, client calls and rota changes often start life as a spreadsheet. Retyping each line into Outlook is where mistakes creep in.
- Name a sheet Events. Use these columns from row 2: A Subject, B Location, C Start (date and time), D End, E Body, F Status.
- Open desktop Outlook before you run the macro.
- Run the code. Each row without Created in column F becomes a calendar entry.
- Check your calendar, then mark the rows you do not want repeated by leaving Created in place.
Option Explicit
Sub CreateOutlookEvents()
Dim olApp As Object
Dim appt As Object
Dim ws As Worksheet
Dim lastRow As Long
Dim r As Long
Set ws = ThisWorkbook.Worksheets("Events")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
MsgBox "Outlook could not be opened."
Exit Sub
End If
For r = 2 To lastRow
If ws.Cells(r, "F").Value <> "Created" Then
Set appt = olApp.CreateItem(1)
appt.Subject = ws.Cells(r, "A").Value
appt.Location = ws.Cells(r, "B").Value
appt.Start = ws.Cells(r, "C").Value
appt.End = ws.Cells(r, "D").Value
appt.Body = ws.Cells(r, "E").Value
appt.Save
ws.Cells(r, "F").Value = "Created"
End If
Next r
End SubThe code uses late binding (the variables are declared As Object), so you do not need to tick any reference in the editor. The number 1 in CreateItem is the Outlook constant for an appointment. Cells C and D must hold real Excel date-times, not text, or Outlook rejects them.
This works with classic desktop Outlook on Windows. The newer web-based Outlook app does not accept VBA automation.
How do I clean messy text with a macro?
Exports from accounting systems, web forms and CRM tools arrive with trailing spaces, double spaces and non-breaking spaces. These break VLOOKUP and XLOOKUP matches without any visible reason.
- Select the range of cells you want to fix. Select at least two cells, or a whole column; only text cells are touched. With a single cell selected, Excel searches the whole used sheet instead.
- Run CleanSelectedText.
- The macro swaps non-breaking spaces (character 160) for normal ones, then applies Excel’s Trim, which also collapses repeated inner spaces.
Option Explicit
Sub CleanSelectedText()
Dim cell As Range
Dim target As Range
On Error Resume Next
Set target = Selection.SpecialCells(xlCellTypeConstants, xlTextValues)
On Error GoTo 0
If target Is Nothing Then Exit Sub
For Each cell In target
cell.Value = Application.WorksheetFunction.Trim(Replace(cell.Value, Chr(160), " "))
Next cell
End SubSpecialCells returns an error when nothing matches, which is why that line sits between two On Error statements. Because the macro writes values over the old text, test it on a copy of your data first. A macro run cannot be undone with Ctrl + Z.
How do I keep an automatic change log?
When several people touch one workbook, someone eventually asks who changed what and when. A log sheet answers that, and a macro makes sure people fill it in.
- Add a sheet named Log. Type Date, User and Note in A1:C1.
- Paste the code and attach it to a button on your main sheet.
- Each click asks for a short note, then appends a row with the date, time and Windows user name.
Option Explicit
Sub AddLogEntry()
Dim logWs As Worksheet
Dim nextRow As Long
Dim note As String
Set logWs = ThisWorkbook.Worksheets("Log")
note = InputBox("What did you change?", "Log entry")
If Len(note) = 0 Then Exit Sub
nextRow = logWs.Cells(logWs.Rows.Count, "A").End(xlUp).Row + 1
logWs.Cells(nextRow, "A").Value = Now
logWs.Cells(nextRow, "B").Value = Environ("Username")
logWs.Cells(nextRow, "C").Value = note
logWs.Cells(nextRow, "A").NumberFormat = "yyyy-mm-dd hh:mm"
End SubThis is a manual log, not an audit trail. It records only what people choose to enter. For tamper-proof tracking you need a database or a document system, a point covered in the limits section below.
How do I reset an Excel form for the next entry?
Quote sheets, order forms and request forms all share one chore: wipe the inputs without wiping the formulas. People do it by hand and, sooner or later, delete a formula.
- Decide which cells are inputs. Here they are C3:C8 and the line-item block B12:E20.
- Paste the code, changing the sheet name and ranges to match your form.
- Run it. A confirmation box appears, then only those ranges are cleared and the cursor returns to C3.
Option Explicit
Sub ResetForm()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Order Form")
If MsgBox("Clear the form?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
ws.Range("C3:C8").ClearContents
ws.Range("B12:E20").ClearContents
ws.Activate
ws.Range("C3").Select
End SubClearContents removes values but keeps formatting and any data validation lists. Use Clear only if you want formatting gone too. For layouts worth copying, see our guide to Excel form templates for business forms. To collect entries in a pop-up form instead, follow our Excel VBA UserForm tutorial.
Which errors will I hit first, and how do I fix them?
Every beginner meets the same handful of messages. Read the error number, find it here, and you can usually fix it in under a minute.
| Message | Usual cause | Fix |
|---|---|---|
| Compile error: Variable not defined | Option Explicit is on and a name is misspelled or never declared | Check the highlighted word against your Dim lines and correct the spelling |
| Run-time error 9: Subscript out of range | The sheet name in the code does not match the tab | Rename the tab or change the text inside Worksheets(“…”) |
| Run-time error 1004 | Invalid sheet name, protected sheet or bad range | Unprotect the sheet, keep names under 31 characters, remove / \ ? * : [ ] |
| Run-time error 76: Path not found | The base folder does not exist or is mistyped | Create the parent folder first, then rerun |
| Run-time error 429: ActiveX component can’t create object | Outlook is missing, is the new web-based version, or is blocked | Use desktop Outlook on Windows and open it first |
| Macros do not appear or buttons do nothing | Workbook saved as .xlsx, or macros disabled | Save as .xlsm and click Enable Content on the yellow bar |
| Run-time error 13: Type mismatch | A cell holds text where a date or number is expected | Convert the cell to a real date or number, or wrap the value in CStr or CDate |
| Screen stays frozen after an error | ScreenUpdating was left False | In the Immediate window (Ctrl + G) type Application.ScreenUpdating = True and press Enter |
When a macro stops, press Debug. The editor highlights the failing line in yellow. Hover over variable names to see their values, or press F8 to step through one line at a time. Stepping is the fastest way to learn what a loop is really doing.
How do I choose between writing macros and buying a VBA tool?
Use this short decision list.
- The job is one small action you do daily and it fits in under 30 lines: write it yourself, using the examples above.
- The job needs a screen, a login or several linked sheets: buy a finished tool and read its source code to learn.
- The job touches the same files as three or four other people: buy a finished tool, because your own macro will need support from you.
- You want to learn VBA properly: do both. Start with tasks 1 to 7, then open a bigger tool and trace how a real application is organized.
For a wider look at ready-made options, see our list of Excel VBA tools for small business, and the 10 ready-made automations it covers. Related tutorials include Power Pivot in Excel for a one-click report and a primer on DAX basics for analysts moving from formulas to measures.
Once the data is clean and automated, the next step is presenting it. Our budget vs actual dashboard in Excel and the guide to Excel sparklines, data bars and icon sets show where macro output often ends up. If your tracking is about people and hours, compare a timesheet template for Excel or a mileage log template for Excel. For a full macro-driven example, look at the visitor management system in Excel VBA.
When is a macro NOT the right answer?
Macros are good at repeating a known routine on one Windows machine. They are poor in these situations:
- Mac, Excel for the web and mobile. Excel for the web does not run VBA. Mac Excel runs it, but file-path and Outlook code differ, so most examples here are Windows-first.
- Many simultaneous editors. Shared cloud workbooks and macros do not mix well. If ten people edit at once, use a database or a cloud workflow tool such as Power Automate.
- Strict audit requirements. A log sheet is editable by anyone with access. Regulated records belong in a system with locked history.
- Heavy data volume. Past roughly a million rows, Excel itself is the limit. Use Power Query, Power Pivot or a proper database.
- IT policy blocks macros. Many companies disable them by default. Ask before you build something others cannot run.
Also remember that macros run with your permissions. Never enable macros in a file from someone you do not know, and keep a backup before running anything that writes or deletes files.
When a macro stops with a run-time error, our VBA try catch and debugging guide shows how to trap it and find the cause.
Frequently asked questions
What are Excel macros for beginners in simple terms?
A macro is a saved list of instructions that Excel repeats on demand. You either record your clicks or write them in VBA. After that, one button or keyboard shortcut runs the whole sequence, so tasks like formatting, copying and saving take seconds and come out identical every time.
Do I need to know programming to use Excel macros?
No. You can record a macro with no code at all, and the examples in this post can be pasted and adjusted by changing sheet names and column letters. Reading each line with the explanations is enough to start. Programming knowledge grows naturally as you fix the first few errors.
Why must I save as .xlsm for macros to work?
The standard .xlsx format cannot store VBA code, so Excel deletes the macros when you save in that format. The .xlsm format keeps them. Always choose Excel Macro-Enabled Workbook in the Save As dialog before closing a workbook that contains code.
Are Excel macros safe to run?
Macros you wrote or trust are safe. Macros from unknown files can delete files or send data, so keep the Trust Center set to disable macros with notification and only click Enable Content for sources you know. Always keep a backup before running code that changes files.
What is the difference between a macro and VBA?
VBA is the programming language and the editor built into Excel. A macro is a single procedure written in that language, usually starting with the word Sub. Recording a macro makes Excel write VBA for you, and writing VBA by hand lets you make macros that are shorter and more flexible.
Why does Option Explicit appear at the top of the code?
Option Explicit forces you to declare every variable with Dim. If you mistype a name, Excel stops with a compile error instead of quietly creating a new empty variable. That catches a whole class of silent bugs, so it is good practice to put it at the top of every module.
Can Excel macros run on a Mac or in Excel for the web?
Excel for the web does not run VBA macros. Excel for Mac does, but code that uses Windows file paths, Outlook automation or some Windows libraries needs changes. If your team uses mixed devices, test every macro on each platform before you rely on it.
How do I run a macro with a button?
On the Developer tab choose Insert, then Button (Form Control). Draw the button on the sheet and pick your macro from the list that appears. Right-click the button to change its label. Clicking it then runs the macro without opening the editor.
What is the quickest way to learn VBA after these seven tasks?
Change one thing at a time in a working macro: a different column, a new sheet name, an extra message box. Step through with F8 to watch variables change. Then read the source of a larger working tool and trace how it is organized into procedures.
Should I buy a VBA template or write the macro myself?
Write it yourself for small, personal routines. Buy a template when the job needs a screen, several linked sheets, or other people using it. The Excel VBA Tools & Utilities Pack costs $63.99 for 8 applications, and single tools such as the Folder Automation Tool cost $6.99.
Get more Excel macro templates
Best value: the Excel VBA Tools & Utilities Pack has 8 premium Excel VBA applications for $63.99, against $105.92 bought individually. It runs offline on Excel 2016, 2019, 2021 and Microsoft 365 for Windows, with editable VBA source you can study.
Prefer to start small? The Folder Automation Tool, Data Segregation Tool and Excel to PDF Converter are $6.99 each, and the Outlook Calendar Events Automation tool is $4.99.
Watch walkthroughs on the NextGen Templates YouTube channel.





