VBA & Macro Problems

Fix Excel VBA Errors When Clearing Dependent Drop-Down Cells

Olivia MillerOlivia Miller Dec 2, 2026 869 views

Question details

The user needs a Worksheet_Change macro to handle changes to multiple rows without a run-time error.

Fix Excel VBA Errors When Clearing Dependent Drop-Down Cells
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A worksheet macro clears a dependent drop-down cell in column J when the corresponding cell in column I changes.
Observed behavior
The macro works for a single row but produces a run-time error when multiple rows are cleared at once.
Before you start

Confirm that column I contains the controlling cells and column J contains the dependent drop-down cells. Open the worksheet's code module in the Visual Basic Editor and locate its existing Worksheet_Change procedure.

Solution 1Recommended

Loop Through Changed Cells to Support Multiple Rows

Use this approach when clearing or pasting multiple cells in column I should also clear the corresponding cells in column J.

Worksheet_Change can receive a range containing multiple cells. Intersecting that range with column I and processing each cell individually avoids treating the entire range as a single cell.

The macro temporarily disables events so clearing column J does not trigger another Worksheet_Change event. Its error handler restores events if an error occurs.

1
Open the worksheet code

In Excel, open the Visual Basic Editor, then find and double-click the affected worksheet in Project Explorer.

2
Replace the event procedure

Replace the existing Worksheet_Change procedure with this code, or merge its logic into the existing procedure if it handles other changes: Private Sub Worksheet_Change(ByVal Target As Range) Dim changedCells As Range Dim cell As Range Dim errorMessage As String Set changedCells = Intersect(Target, Me.Columns(9)) If changedCells Is Nothing Then Exit Sub On Error GoTo ErrorHandler Application.EnableEvents = False For Each cell In changedCells.Cells Me.Cells(cell.Row, 10).ClearContents Next cell Application.EnableEvents = True Exit Sub ErrorHandler: errorMessage = Err.Description Application.EnableEvents = True MsgBox "Unable to clear dependent cells: " & errorMessage, vbExclamation End Sub

3
Test single and multiple rows

Return to the worksheet, change one cell in column I, and then clear several cells in column I at once. Check that the corresponding cells in column J are cleared.

Loop Through Changed Cells to Support Multiple Rows
Scope of the macro: This example clears column J for every changed cell in column I, including headers if they are changed. Adjust the intersected range if only certain rows should be processed. Save the workbook in a macro-enabled format such as .xlsm.
Free Microsoft Office alternative

Manage Dependent Drop-Down Worksheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel workbooks. It can ease migration, although it does not fix an Excel VBA error and macro support varies by WPS edition and platform.

Work with spreadsheet data and drop-down lists in a familiar interface.Open and edit Microsoft Excel formats such as .xlsx and .xlsm.Use a free, lightweight office suite for everyday document work.Move existing spreadsheets into WPS Office without starting from scratch.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro fail when I clear multiple cells?

Worksheet_Change receives all changed cells in Target. Code that assumes Target is a single cell can fail when several cells are cleared or pasted at once. Loop through the relevant cells or exit when Target.CountLarge is greater than one.

Where should I put the Worksheet_Change code?

Open the Visual Basic Editor and double-click the affected worksheet in Project Explorer. Place the event procedure in that worksheet's code module, not in a standard module.

Will ClearContents remove the drop-down list?

ClearContents removes the cell's value or formula but normally leaves its data validation rule intact, so the drop-down remains available.

What if Excel events remain disabled after a macro error?

In the Visual Basic Editor, open the Immediate window and run Application.EnableEvents = True. Add error handling to the macro so it restores events if a later error occurs.

Will this macro run when a formula result changes?

Worksheet_Change does not run solely because a formula recalculates. If column I changes through recalculation rather than a direct edit or paste, a different approach, such as Worksheet_Calculate, is needed.