Hide row based on cell value

glenn0004

New Member
Joined
Nov 15, 2011
Messages
18
I have been asked to create a check sheet where D16 is a drop-down data validation with 26 options, our of those options there are 6 options that do not require addition cells to updated and I would like to hide the rows that contain these calls.

There are two instances of this type of scenario in the same sheet based on different drop downs.

I have currently got the below code which some times (?) works can this be made simpler?

Thanks as always in advance.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect Password:="bunny"
    Select Case Target.Address(False, False)
        Case "D16"
            Rows(24).Hidden = Target.Value <> "Maintenance Inclusive Lease"
            Rows("18:20").EntireRow.Hidden = Target.Value = "Cash"
            Rows("18:20").EntireRow.Hidden = Target.Value = "Cash - 3rd Party"
            Rows("18:20").EntireRow.Hidden = Target.Value = "PO Only"
            
        Case "J32"
            Rows(48).Hidden = Target.Value <> "Minimum Bill"
        
    End Select
    
       ActiveSheet.Protect Password:="bunny"
       
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
These lines have to be ORs otherwise the last line is the one that remains
Code:
            Rows("18:20").EntireRow.Hidden = Target.Value = "Cash"
            Rows("18:20").EntireRow.Hidden = Target.Value = "Cash - 3rd Party"
            Rows("18:20").EntireRow.Hidden = Target.Value = "PO Only"

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    ActiveSheet.Unprotect Password:="bunny"
    
    [color=darkblue]Select[/color] [color=darkblue]Case[/color] Target.Address(False, False)
        [color=darkblue]Case[/color] "D16"
            Rows(24).Hidden = Target.Value <> "Maintenance Inclusive Lease"
            [B]Rows("18:20").EntireRow.Hidden = Target.Value = "Cash" [color=darkblue]Or[/color] Target.Value = "Cash - 3rd Party" [color=darkblue]Or[/color] Target.Value = "PO Only"[/B]
        [color=darkblue]Case[/color] "J32"
            Rows(48).Hidden = Target.Value <> "Minimum Bill"
        
    [color=darkblue]End[/color] [color=darkblue]Select[/color]
    
    ActiveSheet.Protect Password:="bunny"
       
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,293
Members
449,218
Latest member
Excel Master

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