Share via

Hiding different rows in Excel based on multiple criteria

Anonymous
2017-04-28T15:10:50+00:00

I want to be able to hide different rows, depending on different values in a particular row. So, for example, I want to hide rows 126:153 if cell B4 is YES, but also hide rows 154:187 if cell C4 is YES, and hide rows 188:204 if cell D4 is YES.

Searching online, the code below worked for the first part, but I can't work out how to add in the additional conditions.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$4" Then

Cells.EntireRow.Hidden = False

Select Case UCase(Target.Value)

    Case Is = "YES"

        Range("1098").EntireRow.Hidden = True

    Case Is = "NO"

        Range("126:153").EntireRow.Hidden = True

Case Else

    End Select

End If

End Sub

Any help most gratefully received! Thanks

*** Post moved by Moderator to the right category***

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2017-04-29T05:58:21+00:00

Use:

Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Target.Address

    Case Is = "$B$4"

        If UCase(Target.Value) = "YES" Then

            ActiveSheet.Range("126:153").EntireRow.Hidden = True

        Else

            ActiveSheet.Range("126:153").EntireRow.Hidden = False

        End If

    Case Is = "$C$4"

        If UCase(Target.Value) = "YES" Then

            ActiveSheet.Range("154:187").EntireRow.Hidden = True

        Else

            ActiveSheet.Range("154:187").EntireRow.Hidden = False

        End If

    Case Is = "$D$4"

        If UCase(Target.Value) = "YES" Then

            ActiveSheet.Range("188:204").EntireRow.Hidden = True

        Else

            ActiveSheet.Range("188:204").EntireRow.Hidden = False

        End If

End Select

End Sub

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2017-05-16T16:06:22+00:00

    Thanks hugely - worked perfectly! Sorry for replying late, as only just saw this (the site didn't seem to be allowing me to post this question, so I didn't even realize anyone could answer!)...very relieved!

    Thanks again

    Jay

    Was this answer helpful?

    0 comments No comments