Hide rows based on cell value

  • I need to hide different rows based on a cell value.

    The target cell will always be the same, but there are eight different values in the drop down list in the cell.

    I am using Worksheet Change in VBA but it is not working
    Note: A user may select a value from the drop down list in the Target Cell, but may then change their mind and select another value.
    I need only the rows hidden for the selection chosen in the drop down list.
    All other rows should be shown.
    Following is a sample of code I am trying to use

    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Address = "$L$22" Then
            Rows("26:36").Hidden = (Target.Value = "NEW PHONE & MOBILE NUMBER")
            Rows("24:32").Hidden = (Target.Value = "DATACARD FOR LAPTOP")
    End If
    End Sub

    When selecting NEW PHONE & MOBILE NUMBER, rows 26:32 are hidden as expected, but if I then change the selection in the target cell to DATACARD FOR LAPTOP only rows 24:26 are hidden. Rows 27:32 are not hidden

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!