Clear Specific Cells Across Excel Worksheets with VBA
Question details
Clear specified input cells on multiple worksheets without deleting formulas in other cells.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A workbook has drop-down lists and VLOOKUP formulas, with different input cells to reset on each worksheet.
- Observed behavior
- The macro needs to clear only the selected input cells on each worksheet while leaving formulas elsewhere intact.
Check the exact worksheet names and identify the input cells to clear; do not include formula cells. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and ensure you can edit the target cells.
Loop through worksheet names and input cell lists
Use this approach when each worksheet has a different set of cells to reset.
ClearContents removes values and formulas from the specified cells, but leaves formatting and data validation in place. Formulas outside the specified cells remain intact, although their results may recalculate.
The example includes three worksheets. Add an entry for each remaining worksheet and list only cells you want to clear.
In Excel, open Developer > Visual Basic, then choose Insert > Module.
Paste this code into the module: Sub ClearSelectedInputs() Dim targets As Variant Dim i As Long targets = Array( _ Array("CHASSIS PARTS", "C2,C5,E2,E4"), _ Array("ENGINE", "C2,C3,E2,E5"), _ Array("ECU DME", "C2,E2") _ ) For i = LBound(targets) To UBound(targets) ThisWorkbook.Worksheets(targets(i)(0)).Range(targets(i)(1)).ClearContents Next i End Sub
Edit each Array entry in the module to match the exact worksheet name and its input cells. Add entries for the other worksheets, separating entries with commas and using a space followed by an underscore to continue each line.
In Excel, choose Developer > Macros, select ClearSelectedInputs, and click Run. Check that the intended inputs are empty and the formulas remain.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and compatibility with common Excel formats, making it easy to move everyday spreadsheet work. VBA macro support can vary, so verify this macro in your WPS setup.

Frequently Asked Questions
Will ClearContents remove my VLOOKUP formulas?
It removes a formula if the formula cell is included in the specified range. List only input cells in each Array entry to preserve formulas elsewhere.
Will clearing an input cell remove its drop-down list?
ClearContents removes the cell's value but normally leaves its data validation and drop-down list in place.
Can I clear a continuous range instead of individual cells?
Yes. In an Array entry, use a reference such as "C2:C10" instead of a comma-separated list, but make sure the range contains no formulas you want to keep.
Why does the macro fail on a particular cell?
Check whether the worksheet name and range are valid, the sheet is protected, or the cell is part of a merged area. If authorized, unprotect the sheet or select the full merged area before clearing it.
Where should I save the macro?
Save the code in a standard module in the target workbook and save the file as an Excel Macro-Enabled Workbook (.xlsm). The example uses ThisWorkbook to refer to the workbook containing the macro.




