Forum Discussion

Joshua Fischer's avatar
Joshua Fischer
Copper Contributor
Dec 18, 2017

hide or unhide rows depending on a criteria

I am trying to hide or unhide a number or rows depending upon a drop-down box that states Hide or Unhide. Can someone help me with this?

 

2 Replies

  • Hello,

     

    you would need a macro for this. In the following screenshot, cell E2 contains the dropdown with the words hide or unhide. Depending on the selection rows 4 and 5 will be hidden.

     

    The macro code to do this goes like this:

     

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("E2")) Is Nothing Then
        If Target.Value = "unhide" Then
            Rows("4:5").EntireRow.Hidden = False
        Else
            Rows("4:5").EntireRow.Hidden = True
        End If
    End If
    End Sub

    Copy the code, right click on the sheet tab and select View Code. Paste the code into the code window and adjust the references to what you want to hide and where the dropdown is.

     

     

Resources