Auto Hide rows based on cell value

ludlow

Board Regular
Joined
Mar 12, 2013
Messages
87
I wrote the below script, but it is not working as I intended. I would like to view a certain range based on the text in cell A1. However, if i change the value more than once, a number of rows are hidden instead of the expected range. Any help would be greatly appreciated. Thanks.


Private Sub My_test_Case()
Select Case Range("$A$1").Text
Case Is = "tom"
Rows("3:4").Select
Case Is = "steve"
Rows("5:6").EntireRow.Hidden = True
Case Is = "tom"
Rows("7:8").EntireRow.Hidden = True
Case Is = "rich"
Rows("9:14").EntireRow.Hidden = True
Case Else
Rows("3:14").Select
Selection.EntireRow.Hidden = False

End Select
End Sub
 
I'm on my iPad so can't type a lot. You need to change your first couple rows.

Step 1 see if the Target cell is A1
Step 2 change your Select Case statement
Code:
If Target.Address = "$A$1" Then
    Select Case Target.Value
       Case xxx

       Case yyy
    End Select
End If
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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