VBA & Macro Problems

Create an Excel Button to Clear Cells on Multiple Worksheets

Camila MilosovichCamila Milosovich Nov 22, 2026 870 views

Question details

Create a button that clears the same range on three Excel worksheets each month.

Create an Excel Button to Clear Cells on Multiple Worksheets
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user wants to clear cells C2:C32 on worksheets J09, J10, and J11 with one button.
Observed behavior
A macro should clear the specified ranges; a worksheet name mismatch can cause a Subscript out of range error.
Before you start

Check that the worksheet tabs are named exactly J09, J10, and J11, and that C2:C32 contains only data you intend to clear. The macro below also removes formatting from those cells.

Solution 1Recommended

Add a VBA macro and assign it to an Excel button

Use this method to clear the three ranges at once and run the macro from a worksheet button.

1
Open the VBA editor

In desktop Excel, open the workbook containing the three worksheets and press Alt+F11 to open the Visual Basic Editor.

2
Insert the macro

Select the workbook's project, choose Insert > Module, and paste: Sub ClearData() Dim Sht As Variant For Each Sht In Array("J09", "J10", "J11") ThisWorkbook.Worksheets(Sht).Range("C2:C32").Clear Next Sht End Sub

3
Save and test

Return to Excel and choose File > Save As. Select Excel Macro-Enabled Workbook (*.xlsm), then press Alt+F8, select ClearData, and click Run. Enable macros if Excel prompts you and you trust the workbook.

4
Add a button

On the Developer tab, choose Insert > Button under Form Controls. Draw the button on a worksheet, select ClearData in the Assign Macro dialog, and click OK.

5
Check the result

Click the button and inspect C2:C32 on J09, J10, and J11. If an error appears, choose Debug and check the sheet names on the highlighted line against the worksheet tabs.

Add a VBA macro and assign it to an Excel button
Keep formatting if needed: Clear removes cell contents and formatting. To remove values and formulas while preserving formatting, replace .Clear with .ClearContents in the macro.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Excel formats, making it easy to bring existing files into WPS. VBA support can vary by edition and platform, so check macro compatibility before relying on this Excel button.

Open and edit Microsoft Excel XLSX files.Work with ranges across multiple worksheet tabs in WPS Spreadsheets.Use a familiar spreadsheet interface for an easier transition from Excel.Get a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro show a Subscript out of range error?

The macro may not find one of the named sheets in the workbook that contains the code. Click Debug in the error dialog, then compare J09, J10, and J11 in the Array with the worksheet tab names, including spaces.

How can I clear values without removing cell formatting?

In the Visual Basic Editor, replace .Clear with .ClearContents on the line containing Range("C2:C32"). This removes values and formulas but keeps formatting.

Where is the Developer tab in Excel?

If it is hidden, use File > Options > Customize Ribbon in Excel for Windows, select Developer, and click OK. Then use Developer > Insert to add a Form Controls button.

Why must I save the workbook as an XLSM file?

The XLSM format retains VBA macros. Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm); a standard XLSX file cannot retain the macro.