Excelme at work
New Member
- Joined
- Feb 7, 2018
- Messages
- 18
Hi all,
I have searched this forum for an answer but my understanding of VBA does not allow me to combine everything I have read.
I have created a spreadsheet which has the dates for an entire year listed across row from E3 : BK3
Cell D1 is a drop down menu with Jan - Dec and "Annual" as options.
I essentially want all columns except the corresponding month to hide when one is selected and all columns visible when "annual" is selected. Is this possible?
I used this forum to create a code which allows me to set "If January selected then hide all other columns"
However, as soon as I try to introduce an alternative outcome it does not work as required.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 And Target.Row = 1 And Target.Value = "January" Then
Columns("E:AI").Select
Selection.EntireColumn.Hidden = False
Else
Columns("E:NJ").Select
Selection.EntireColumn.Hidden = True
End If
If Target.Column = 4 And Target.Row = 1 And Target.Value = "February" Then
Columns("AJ:BK").Select
Selection.EntireColumn.Hidden = False
Else
Columns("E:NJ").Select
Selection.EntireColumn.Hidden = True
End If
End Sub
I have searched this forum for an answer but my understanding of VBA does not allow me to combine everything I have read.
I have created a spreadsheet which has the dates for an entire year listed across row from E3 : BK3
Cell D1 is a drop down menu with Jan - Dec and "Annual" as options.
I essentially want all columns except the corresponding month to hide when one is selected and all columns visible when "annual" is selected. Is this possible?
I used this forum to create a code which allows me to set "If January selected then hide all other columns"
However, as soon as I try to introduce an alternative outcome it does not work as required.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 And Target.Row = 1 And Target.Value = "January" Then
Columns("E:AI").Select
Selection.EntireColumn.Hidden = False
Else
Columns("E:NJ").Select
Selection.EntireColumn.Hidden = True
End If
If Target.Column = 4 And Target.Row = 1 And Target.Value = "February" Then
Columns("AJ:BK").Select
Selection.EntireColumn.Hidden = False
Else
Columns("E:NJ").Select
Selection.EntireColumn.Hidden = True
End If
End Sub