A
Ayo
I have this Worksheet event that I am trying to use to hide rows and columns
based on the value in Range("A2"). The code looks OK and it doesn't give any
error except that it doesn't quite does want it is intended to do.
For instance, when it is run, columns A:L are hidden everytime. This is not
the intent for the code and I can't figure out why it is doing this. Any
helpful insight will be greatly appreciated.
The entire code follows:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Me.Rows("6:17").Select
Selection.EntireRow.Hidden = False
Me.Columns("D:AB").Select
Selection.EntireColumn.Hidden = False
If Target.Address() = "$A$2" Then
Application.EnableEvents = False
Select Case Target.Value
Case "NLP1 Infill: Milestone Completion Counts by Market"
Me.Range("E:F,I:K,N:N,P:Q,U:W,AA:AA").Select
Selection.EntireColumn.Hidden = True
Me.Range("7:7,12:12,15:15").Select
Selection.EntireRow.Hidden = True
Case "NLP2: Milestone Completion Counts by Market"
Me.Range("E:K,N:N,W:W,Y:AA").Select
Selection.EntireColumn.Hidden = True
Me.Range("9:9,11:11,13:13").Select
Selection.EntireRow.Hidden = True
Case "NLP3: Milestone Completion Counts by Market"
Me.Range("E:K,M:M,U:Z").Select
Selection.EntireColumn.Hidden = True
Me.Range("13:13").Select
Selection.EntireRow.Hidden = True
End Select
End If
Application.EnableEvents = True
End Sub
based on the value in Range("A2"). The code looks OK and it doesn't give any
error except that it doesn't quite does want it is intended to do.
For instance, when it is run, columns A:L are hidden everytime. This is not
the intent for the code and I can't figure out why it is doing this. Any
helpful insight will be greatly appreciated.
The entire code follows:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Me.Rows("6:17").Select
Selection.EntireRow.Hidden = False
Me.Columns("D:AB").Select
Selection.EntireColumn.Hidden = False
If Target.Address() = "$A$2" Then
Application.EnableEvents = False
Select Case Target.Value
Case "NLP1 Infill: Milestone Completion Counts by Market"
Me.Range("E:F,I:K,N:N,P:Q,U:W,AA:AA").Select
Selection.EntireColumn.Hidden = True
Me.Range("7:7,12:12,15:15").Select
Selection.EntireRow.Hidden = True
Case "NLP2: Milestone Completion Counts by Market"
Me.Range("E:K,N:N,W:W,Y:AA").Select
Selection.EntireColumn.Hidden = True
Me.Range("9:9,11:11,13:13").Select
Selection.EntireRow.Hidden = True
Case "NLP3: Milestone Completion Counts by Market"
Me.Range("E:K,M:M,U:Z").Select
Selection.EntireColumn.Hidden = True
Me.Range("13:13").Select
Selection.EntireRow.Hidden = True
End Select
End If
Application.EnableEvents = True
End Sub