Hiding rows based on input parameter

Niss1

New Member
Joined
Jul 8, 2011
Messages
20
In my excel sheet I have a drop down box.
If the user selects "Parameter1" i would like to unhide the next 5 rows, if he chooses something else then i would like to hide those 5 rows.

This happens several times in my worksheet and i would like to have something where i do not need to hardcode the row numbers for each case.
 
If you have lots of validation cells, you could try

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If hasValidation(Target) Then
        Application.EnableEvents = False
            With Target
            .Offset(1).Resize(5).EntireRow.Hidden = .Value <> "Parameter1"
        End With
        Application.EnableEvents = True
    End If
End Sub
Function hasValidation(ByVal rng As Range) As Boolean
    On Error GoTo noValidation
    hasValidation = (rng.Validation.Type = 3)
noValidation:
End Function
You can add more without changing the code.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,225,151
Messages
6,183,197
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top