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.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this in the module for the worksheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$A$1" Then
        With Target
            .Offset(1).Resize(5).EntireRow.Hidden = .Value <> "Parameter1"
        End With
    End If
    Application.EnableEvents = True
End Sub

Change the reference to A1 to suit.
 
Upvote 0
Thank you for a fast reply!

This works perfect for 1 cell/value.

Is there any way to make this applicable for the entire sheet(for every time there is a "Parameter1)" or do i have to hardcode this to apply for every single cell where i have this dropbox?
 
Upvote 0
If the dropboxes are populated from ranges, I think we could make it work over the full sheet without any hard coding.
 
Upvote 0
For A1 and A7:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$A$1" Then
        With Target
            .Offset(1).Resize(5).EntireRow.Hidden = .Value <> "Parameter1"
        End With
    ElseIf Target.Address = "$A$7" Then
        With Target
            .Offset(1).Resize(5).EntireRow.Hidden = .Value <> "Parameter1"
        End With
    End If
    Application.EnableEvents = True
End Sub

Add more ElseIfs if necessary.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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