VBA Code to hide/unhide rows when a something is selected from drop down list.

Essencex

New Member
Joined
Aug 7, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi I cannot figure this out for the life of me!
I need a code that will unhide rows 8-47 when 'Yes - Answer questions below' is selected in drop down list of cell E7.

The same goes for the following on the same sheet:
I need a code that will unhide rows 57-91 when 'Yes - Answer questions below' is selected in drop down list of cell E56.
*I guess I can just copy and paste the code for above and change it slightly for the second request?

hopefully someone can help :biggrin:
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
@Essencex Welcome
Try like this Change Event code. Paste into the sheet's code pane.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Not Target = "Yes - Answer questions below" Then Exit Sub
    Select Case Target.Address
    Case "$E$7"
        Range("E8:E47").Rows.EntireRow.Hidden = False
        
    Case "$E$56"
        Range("E57:E91").Rows.EntireRow.Hidden = False
    Case Else
    End Select
    
End Sub
HTH
 
Upvote 0
Hi Tony, this absolutely worked thank you!! Ive tested it and near perfect...how do I, if the word 'Yes - Answer questions below' is de-selected from list how do i get it back to 're-hiding' the rows?
 
Upvote 0
Hi, Try like..

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim HideRows As Boolean
    If Target.Count > 1 Then Exit Sub
    HideRows = Not Target = "Yes - Answer questions below"
    Select Case Target.Address
    Case "$E$7"
        Range("E8:E47").Rows.EntireRow.Hidden = HideRows
        
    Case "$E$56"
        Range("E57:E91").Rows.EntireRow.Hidden = HideRows
    Case Else
    End Select
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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