Hide/Unhide Rows based on cell values

kthony

New Member
Joined
Jan 2, 2023
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi, for some reason this will not run. I have tried multiple time to hide and unhide based on cell value. Any help would be greatly appreciated!

Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("C5"), Target) Is Nothing Then
Application.EnableEvents = False
Me.Unprotect Password:="secret"
Range("A6:A22").EntireRow.Hidden = True
Select Case Range("C5").Value
Case "Annual Salary"
Range("A7").EntireRow.Hidden = False
Case "Hourly Wage"
Range("A16").EntireRow.Hidden = False
End Select
Me.Protect Password:="secret"
Application.EnableEvents = True
End If
End Sub
Sub Test(ByVal Target As Range)
If Not Intersect(Range("C5"), Target) Is Nothing Then
Application.EnableEvents = False
Range("6:22").EntireRow.Hidden = True
Select Case Range("c5").Value
Case "Annual Salary"
Range("a7").EntireRow.Hidden = False
Case "Hourly Range"
Range("a16").EntireRow.Hidden = False
End Select
Application.EnableEvents = True
End If
End Sub

1672707154766.png

I am trying to hide/unhide rows based on c5. then based on the result of c5 if c7 unhidden and value select on hide either row c10:c12 or c8:c9.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I forgot to mention c6:c22 is completely hidden to start with
 
Upvote 0
The code works fine for me.
1) do you have the code in the Code module of that particular sheet.
2) the select case statement is case senstive - does your C5 drop down box have exactly Annual Salary and Hourly Rate, same case and no leading or trailing spaces.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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