VBA & Macro Problems

Clear Specific Cells Across Excel Worksheets with VBA

Tauseeq MagsiTauseeq Magsi Nov 25, 2026 870 views

Question details

Clear specified input cells on multiple worksheets without deleting formulas in other cells.

Clear Specific Cells Across Excel Worksheets with VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open Developer > Visual Basic, then choose Insert > Module.

2
Add the macro

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

3
Complete and check the lists

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.

4
Run the macro

In Excel, choose Developer > Macros, select ClearSelectedInputs, and click Run. Check that the intended inputs are empty and the formulas remain.

Loop through worksheet names and input cell lists
If the macro stops with an error: Check the worksheet names and cell references first. Protected cells or merged cells can also prevent clearing; unprotect the sheet if authorized or adjust the selection to include the full merged area.
Free Microsoft Office alternative

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.

Edit and manage input cells across spreadsheet worksheetsOpen and work with Microsoft Excel XLSX and XLS filesUse a familiar interface for everyday spreadsheet tasksMove compatible spreadsheets between Excel and WPS Office
microsoft office alternative - wps office

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.