Excel VBA: Hide Rows When Values Change on Another Worksheet
Question details
The user wants to hide or show rows on one worksheet when selections on another worksheet change formula results.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- Worksheet B contains formulas that depend on dropdown selections on Worksheet A.
- Observed behavior
- A Worksheet_Change event on Worksheet B does not run when its formula results change through recalculation.
Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file. Confirm the worksheet names and the columns used for dropdowns, row values, and the last-row calculation; adjust the examples if needed.
Run a Shared Row-Hiding Macro When Worksheet A Changes
Use this approach when a dropdown in Worksheet A is the known trigger for updating rows on Worksheet B.
The example watches column C on Worksheet A. On Worksheet B, it checks values in column D through the last used row in column E: 0 hides a row, while 1 or a blank shows it. Other values leave the row's current visibility unchanged.
Press Alt+F11 to open the Visual Basic Editor. Select the workbook, choose Insert > Module, and paste: Public Sub HideRowsOnB() Dim ws As Worksheet, c As Range Dim lastRow As Long Dim eventsWereEnabled As Boolean Dim errorText As String eventsWereEnabled = Application.EnableEvents On Error GoTo CleanUp Application.EnableEvents = False Set ws = ThisWorkbook.Worksheets("B") lastRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row For Each c In ws.Range("D1:D" & lastRow) If Not IsError(c.Value2) Then If Len(CStr(c.Value2)) = 0 Then c.EntireRow.Hidden = False ElseIf c.Value2 = 0 Then c.EntireRow.Hidden = True ElseIf c.Value2 = 1 Then c.EntireRow.Hidden = False End If End If Next c CleanUp: errorText = Err.Description Application.EnableEvents = eventsWereEnabled If Len(errorText) > 0 Then MsgBox errorText, vbExclamation End Sub
In the editor's Project pane, double-click Worksheet A and paste this code into its worksheet module: Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Me.Columns("C")) Is Nothing Then Exit Sub ThisWorkbook.Worksheets("B").Calculate HideRowsOnB End Sub
Return to Excel and change a dropdown in column C on Worksheet A. Check that Worksheet B recalculates and that rows with 0 in column D are hidden.

Run the Row-Hiding Macro After Worksheet B Recalculates
Use this alternative when Worksheet B's formula results can change for reasons other than edits to Worksheet A's dropdowns.
Work with Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. It supports common Excel formats for easier migration, but it does not fix Microsoft Excel's VBA events; macro compatibility can vary.

Frequently Asked Questions
Why doesn't Worksheet_Change run when a formula result changes?
Worksheet_Change responds to cell edits, not changes caused only by formula recalculation. Put the change event on the sheet where the input is edited, or use Worksheet_Calculate on the formula sheet.
Where should I put the row-hiding procedure?
In the Visual Basic Editor, select the workbook and choose Insert > Module. Put the shared procedure there, and place each Worksheet_Change or Worksheet_Calculate event in its corresponding worksheet's code module.
What if Application.EnableEvents is left turned off?
In the Visual Basic Editor, open View > Immediate Window, type Application.EnableEvents = True, and press Enter. The sample procedure also restores the previous event setting if it encounters an error.
Can I hide rows if recipients disable macros?
VBA events will not run when macros are disabled. As an alternative, add a filter using Data > Filter and ask users to filter the value column manually.




