Hide non-contiguous rows based on Yes/No dropdown

gtirrell

New Member
Joined
Jun 16, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
To preface, I have searched the forum for an answer to my question since this must be pretty basic, but have been unable to make it work.

I need a VBA code which only needs to work on 1 specific sheet. Based on a dropdown answer in cell F1 (Yes or No), I need to hide a number of non-contiguous rows. Here, "Yes" would hide the rows and "No" would unhide. The rows (right now) are 8, 29, 30, 31, and 83.

Thank you in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in F1.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Address(0, 0) <> "F1" Then Exit Sub
    Select Case Target.Value
        Case "Yes"
            Range("8:8, 29:29, 30:30, 31:31, 83:83").EntireRow.Hidden = False
        Case "No"
            Range("8:8, 29:29, 30:30, 31:31, 83:83").EntireRow.Hidden = True
    End Select
End Sub
 
Upvote 0
Solution
Perfect, I was relatively close but clearly missing some key code. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,845
Members
449,193
Latest member
MikeVol

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