How to Automatically Hide Rows in Excel Based on Cell Value

Want to make your Excel sheet cleaner and more dynamic? You can automatically hide rows based on specific cell values using filters, conditional formatting tricks, or simple VBA code. This tutorial will walk you through all the methods.

1. Hide Rows Using Filters (No Code Needed)

The easiest way to hide rows is by using Excel’s built-in filters.

Steps:

  1. Select your dataset.
  2. Go to Data > Filter.
  3. Click the dropdown on the column you want to use for filtering.
  4. Uncheck the value you want to hide (e.g., “0” or “N/A”).

This doesn’t delete any data—it just hides the rows from view.

2. Automatically Hide Rows Using VBA

If you want Excel to hide rows automatically based on cell values, use this simple macro:


Sub HideRowsWithZero()
    Dim cell As Range
    For Each cell In Range("B2:B100")
        If cell.Value = 0 Then
            cell.EntireRow.Hidden = True
        End If
    Next cell
End Sub

How to Use:

  • Press Alt + F11 to open the VBA editor
  • Insert a new module
  • Paste the code and run it

💡 Tip: Change the range and value as needed. For example, hide rows with “N/A”, “No”, or blank cells.

3. Use Conditional Formatting to Highlight Instead

If you prefer not to hide rows, you can highlight them for review. Select your range and go to:

  • Home > Conditional Formatting > New Rule
  • Use a formula like =B2=0 and apply a grey fill
See also  How To Create An Attendance Sheet In Excel

This visually separates unwanted rows without removing them.

4. Dynamic Hiding with Checkbox (Advanced)

You can create a checkbox linked to VBA code to toggle row visibility. This is useful for dashboards or templates where you want more control.

Here’s sample VBA to attach to a checkbox (Form Control):


Sub ToggleHideRows()
    Dim cell As Range
    Dim isChecked As Boolean
    isChecked = Worksheets("Sheet1").CheckBoxes("CheckBox1").Value = 1
    
    For Each cell In Range("B2:B100")
        If cell.Value = 0 Then
            cell.EntireRow.Hidden = isChecked
        End If
    Next cell
End Sub