crasherar82
New Member
- Joined
- Jul 23, 2018
- Messages
- 4
I am struggling with a MACRO. I need to hide a range of columns based on the selection of a dropdown menu. Menu selections are 1-5 with the range of hidden columns changing based on the selection. I am pretty new at using macros and I am having a hard time. The macro runs but it hides columns starting from the target field. Here is the marco I input
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = 1 Then
Application.Columns("E:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 2 Then
Application.Columns("G:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 3 Then
Application.Columns("I:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 4 Then
Application.Columns("K:L").Select
Application.Selection.EntireColumn.Hidden = True
End If
End Sub
When exectued it hides columns B:L regardless of the selection in B5. Please help/advise.
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = 1 Then
Application.Columns("E:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 2 Then
Application.Columns("G:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 3 Then
Application.Columns("I:L").Select
Application.Selection.EntireColumn.Hidden = True
ElseIf Range("B5") = 4 Then
Application.Columns("K:L").Select
Application.Selection.EntireColumn.Hidden = True
End If
End Sub
When exectued it hides columns B:L regardless of the selection in B5. Please help/advise.