To clear the contents of a worksheet in VBA, use Worksheets("Sheet1").Cells.ClearContents (or ActiveSheet.Cells.ClearContents). That single line removes every value, formula and text entry on the sheet while leaving the sheet's formatting, comments and shapes untouched. A bare .Clear instead of .ClearContents wipes formatting too, so choose the method that matches what you want to keep.
What You'll Need
- An Excel workbook with one or more worksheets you want to clear.
- Access to the Visual Basic Editor (Alt+F11 on Windows, Fn+Alt+F11 on most Mac keyboards).
- The Developer tab enabled, or willingness to open the editor with the keyboard shortcut.
- Macro security settings that allow macros to run — typically "Disable all macros with notification", then click Enable Content when prompted.
- A backup copy of the workbook, at least for your first attempt.
- If you plan to save the macro in the workbook, save it as an .xlsm file.
A quick note on naming: menu and button labels in Excel can differ slightly by version, platform and region, so if a label below reads a little differently on your copy, look for the closest equivalent.
Step-by-Step
- Save a copy of the workbook. Clearing contents cannot be undone by the normal Undo button — it is not in Excel's undo stack. Close the workbook, copy the file in File Explorer or Finder, and reopen the copy to work on. This is the single most important step for a first attempt.
- Open the Visual Basic Editor. Press Alt+F11 (Windows) or Fn+Alt+F11 (Mac). Alternatively, on the Developer tab choose Visual Basic. If the Developer tab is hidden, right-click the ribbon, choose Customize the Ribbon, and tick Developer in the right-hand list.
- Insert a standard module. In the editor, open the Insert menu and choose Module. A blank code window appears under a new module node in the Project Explorer. Standard modules hold macros you can run from Excel with Alt+F8.
- Write the simplest macro. Type the following into the module:
This clears whatever sheet is active when you run it, so it is safe for experimenting but easy to run on the wrong sheet by accident.Sub ClearSheet()
ActiveSheet.Cells.ClearContents
End Sub - Prefer naming the sheet explicitly. Replace the middle line with
Worksheets("Data").Cells.ClearContents, substituting your real sheet name. Naming the sheet removes the risk of clearing the wrong tab, and the macro will fail loudly if the name is misspelled rather than doing unexpected damage. - Handle sheet names that contain spaces. Sheet names with spaces work fine inside the quotes, but if you refer to a sheet by its code name (the name shown before the parentheses in the Project Explorer) you do not quote it at all. When in doubt, use the
Worksheets("...")form. - Run the macro. Switch back to Excel, press Alt+F8, select ClearSheet and click Run. You can also press F5 inside the editor while the cursor is inside the procedure.
- Verify the result. Check that the values are gone but that fills, borders, number formats, column widths, comments and charts are still in place. If formatting disappeared, you used
Clearinstead ofClearContents. - Clear a specific range instead of the whole sheet if you only want part of it gone. For example,
Worksheets("Data").Range("A2:D100").ClearContentsclears that block and leaves row 1 headers intact — often exactly what you want when clearing data but keeping titles. - Clear several sheets in one pass with a loop:
Dim ws As Worksheet, thenFor Each ws In ThisWorkbook.Worksheets, thenws.Cells.ClearContents, thenNext ws. Be careful — this hits every sheet, including instruction tabs and lookup tables. Restrict it to named sheets instead if any sheet must survive. - Decide whether formatting should also go. Use
.Clearto remove contents, formats, comments and conditional formatting on the cells. Use.ClearFormatsfor formatting only, and.ClearCommentsfor notes only. There is no single command that clears values but keeps conditional formatting rules, so delete those manually if needed. - Save the workbook as .xlsm. Use File > Save As and pick Excel Macro-Enabled Workbook. A plain .xlsx save discards the module and you will lose the macro.
Common Mistakes
- Using
.Clearwhen you meant.ClearContents. This strips number formats and fills and is a common cause of a sheet that suddenly looks broken. - Referencing
ActiveSheetin a macro you will reuse. Whatever tab happens to be selected gets cleared. Name the sheet. - Clearing the wrong sheet because of a typo.
Worksheets("data")andWorksheets("Data")are different to VBA; sheet name comparison is not case-insensitive in the way you might expect, and a mismatch raises a subscript out of range error. - Expecting Ctrl+Z to bring data back. After a macro runs, Undo does nothing for the cleared cells. Restore from your backup or a previous version.
- Forgetting that
Cells.ClearContentsalso clears cells holding formulas that other sheets depend on. Downstream formulas will return zeros, blanks or #REF! errors. - Saving as .xlsx. The macro vanishes on save and only reappears if you saved a copy elsewhere.
- Clearing protected sheets. Without the password,
ClearContentsfails with a runtime error. Unprotect first withws.Unprotect "password", then reprotect.
Tips
- Add a confirmation prompt before destructive macros:
If MsgBox("Clear the sheet?", vbYesNo) = vbNo Then Exit Sub. It takes one line and saves an afternoon. - Turn off screen updating (
Application.ScreenUpdating = False) and switch it back on at the end when clearing many sheets; it makes the macro noticeably faster on large workbooks. - Clear only the used range with
ws.UsedRange.ClearContentsif your sheet has stray formatting far down; it clears just the populated block. - Keep a separate "template" sheet and copy it rather than clearing and rebuilding — copying is often cleaner than restoring formats.
- Store sheet names in a constant at the top of the module so you change them in one place.
- Test on a copy until you trust the macro; then consider adding it to the Quick Access Toolbar via File > Options > Quick Access Toolbar.
Troubleshooting
Nothing happens when you run it. Check that the macro is in a standard module, not a sheet module, and that macros are enabled. Look at the Immediate window (Ctrl+G) after adding a Debug.Print ActiveSheet.Name line to confirm which sheet was targeted.
Run-time error 9, subscript out of range. The sheet name in your code does not match any tab. Check spelling, leading or trailing spaces, and remember that a workbook referenced by Workbooks("name.xlsx") must be open.
Run-time error 1004. Usually a protected sheet, a protected workbook structure, or a worksheet that is not actually a worksheet (a chart sheet, for example). Unprotect and retry.
Formatting disappeared. You used Clear. There is no built-in way to undo it in code — restore from the backup copy or reapply formats from a template sheet.
The macro is greyed out or blocked. Check File > Options > Trust Center > Trust Center Settings > Macro Settings, and make sure the file is not blocked in its properties or sitting in an untrusted location.
Data is still there after running. Confirm you saved and ran the current version of the module, and that the target sheet is not hidden with data sitting on a differently named visible sheet. Also check whether the data is in a table object — ClearContents on the sheet's cells still works, but rows outside the table's range are unaffected.
Frequently Asked Questions
Does ClearContents delete formulas?
Yes. Formulas are contents, so they are removed along with values and text. Only formatting, comments, shapes and data validation settings remain.
What is the difference between Clear, ClearContents and Delete?
Clear removes contents and formatting; ClearContents removes only values, formulas and text; Delete removes the cells themselves and shifts the remaining cells up or left, which can break references.
Can I clear a sheet without deleting its headers?
Yes. Clear a specific range such as Range("A2:D1000") rather than the whole sheet, or use Rows("2:1000").ClearContents to leave row 1 intact.
Can the macro be undone?
No — VBA actions are not recorded in Excel's undo history. Close without saving, or restore from a backup or a previous version.
Will clearing contents delete charts and shapes?
No. Charts, shapes, pictures and buttons float above the cells and survive both ClearContents and Clear.
How do I clear several sheets at once?
Loop through the sheets you want and call ClearContents on each, naming them individually so sheets holding reference data are not touched.