VBA macro generator for Excel tasks you repeat every week
Every Monday you split one sheet into one file per region, or reformat the same export. A VBA macro can do it in one click. Describe the task to your todo.is agent and it writes commented VBA code, explains where to paste it, and adds safety checks so the macro can't wreck your workbook if the data changes.
The prompt
- Write an Excel VBA macro that [WHAT THE MACRO SHOULD DO]. My workbook: [SHEETS AND COLUMNS] (sample attached). I use [EXCEL VERSION AND SYSTEM]. Comment every block, turn off screen updating while it runs, check the expected sheet and headers exist before changing anything, and show a message when it finishes with what it did. Give me step-by-step instructions to add it, save as .xlsm and attach it to a button. Also explain how to undo it, since macros can't be undone with Ctrl+Z.
What to change
- [WHAT THE MACRO SHOULD DO]: E.g. "split the Orders sheet into one new workbook per Region, saved as PDF and .xlsx in a folder".
- [SHEETS AND COLUMNS]: E.g. "Sheet 'Orders' with headers in row 1: Date, Region, Rep, Amount". Attach a copy with fake data.
- [EXCEL VERSION AND SYSTEM]: E.g. "Microsoft 365 on Windows 11", "Excel 2019", "Excel for Mac" (some file and folder code differs on Mac).
Example result
- SplitByRegion: one workbook per region
- The macro (core part)
- Sub SplitByRegion()
- Dim ws As Worksheet, regions As Object, r As Long, lastRow As Long
- Dim key As Variant, outWb As Workbook, folder As String
- Set ws = ThisWorkbook.Sheets("Orders")
- If ws.Range("B1").Value <> "Region" Then
- MsgBox "Column B header should be 'Region'. Nothing was changed.", vbExclamation
- Exit Sub
- End If
- folder = ThisWorkbook.Path & "\Regions " & Format(Date, "yyyy-mm-dd") & "\"
- If Dir(folder, vbDirectory) = "" Then MkDir folder
- Application.ScreenUpdating = False
- Set regions = CreateObject("Scripting.Dictionary")
- lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
- For r = 2 To lastRow
- regions(ws.Cells(r, 2).Value) = True
- Next r
- For Each key In regions.Keys
- ws.Range("A1").AutoFilter Field:=2, Criteria1:=key
- Set outWb = Workbooks.Add
- ws.UsedRange.SpecialCells(xlCellTypeVisible).Copy outWb.Sheets(1).Range("A1")
- outWb.SaveAs folder & key & ".xlsx", FileFormat:=xlOpenXMLWorkbook
- outWb.Close False
- Next key
- ws.AutoFilterMode = False
- Application.ScreenUpdating = True
- MsgBox regions.Count & " region files saved in " & folder, vbInformation
- End Sub
- How to add it
- • Press Alt+F11 to open the VBA editor
- • Insert > Module, then paste the code
- • Save the workbook as Excel Macro-Enabled Workbook (.xlsm)
- • Back in Excel: Developer > Insert > Button, draw it, and pick SplitByRegion
- • No Developer tab? File > Options > Customize Ribbon > tick Developer
- Safety
- • It never changes or deletes rows in Orders; it only filters, then removes the filter
- • It stops with a message if the Region header has moved
- • Output goes to a new dated folder, so earlier runs aren't overwritten
- • Ctrl+Z can't undo a macro. Keep a saved copy before trying any new macro
- Tested logic
- On your sample (620 rows, 5 regions) the steps produce 5 files: North 141 rows, South 118, East 97, West 160, Central 104.
How to do it with todo.is
- Copy the prompt and describe the task and your sheet layout.
- Attach a copy of the workbook with fake data in todo.is, or send it to your agent.
- Your agent sends the commented VBA code, setup steps and a .bas file you can import.
- Paste it into a module, save as .xlsm and try it on a copy first.
- Tell it what went wrong ("error 1004 on line 22") and it fixes the code.
Tips for a better result
- Try every new macro on a copy of the workbook. Macros can't be undone with Ctrl+Z.
- Excel for Mac handles file paths and some objects differently. Say if you're on a Mac.
- Ask for headers to be found by name rather than by column letter, so the macro survives a new column.
- If your company blocks macros, ask for an Office Scripts or Power Query version instead.
- If you'd rather not run code at all, attach the file and let your agent do the split and send the results.
VBA macro generator: FAQ
- How do I run a VBA macro in Excel? Press Alt+F8, pick the macro and click Run, or attach it to a button. The file must be saved as .xlsm, and you may need to click Enable Content when you open it.
- Is VBA safe to use? Macros you write or understand are safe. Macros in files from unknown senders can be harmful, which is why Excel blocks them by default. Read the comments in the code before you run it.
- Does VBA work in Excel Online or Google Sheets? No. VBA runs in desktop Excel on Windows and Mac. Excel Online uses Office Scripts, and Google Sheets uses Apps Script.
- Can the agent run the macro for me? It doesn't run VBA itself. It can check the logic, and it can do the same task in Python on your attached file if you just want the result.
JavaScript is required to use the todo.is app.