thelostscott
Board Regular
- Joined
- May 7, 2010
- Messages
- 226
Hi all,
I'm trying to get a worksheet to hide certain rows depending on the selection of a DV list. What I have so far is this:
It seems to work ok, however i'm not sure whether a "Worksheet_Change" event is the best way to go as every time I enter data into the tables it re-runs the Macro. How do I get it to only run the Macro when a selection is made in "C2" (apart from adding a button click)?
I'm trying to get a worksheet to hide certain rows depending on the selection of a DV list. What I have so far is this:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
On Error Resume Next
If Range("C2") = "Option 1" Then
Rows("3:400").EntireRow.Hidden = True
Rows("3:100").EntireRow.Hidden = False
End If
If Range("C2") = "Option 2" Then
Rows("3:400").EntireRow.Hidden = True
Rows("201:298").EntireRow.Hidden = False
End If
If Range("C2") = "Option 3" Then
Rows("3:400").EntireRow.Hidden = True
Rows("300:397").EntireRow.Hidden = False
End If
If Range("C2") = "Option 4" Then
Rows("3:400").EntireRow.Hidden = True
Rows("102:199").EntireRow.Hidden = False
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
It seems to work ok, however i'm not sure whether a "Worksheet_Change" event is the best way to go as every time I enter data into the tables it re-runs the Macro. How do I get it to only run the Macro when a selection is made in "C2" (apart from adding a button click)?