Create an Excel Button to Clear Cells on Multiple Worksheets
Question details
Create a button that clears the same range on three Excel worksheets each month.

- 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.
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.
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.
In desktop Excel, open the workbook containing the three worksheets and press Alt+F11 to open the Visual Basic Editor.
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
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.
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.
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.

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.

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.




