First post and desperate to stop wasting my time trying to piece together bits of what I need from different searches. I am pretty new to writing code and will admit I don't always understand every line of code I find when searching.
I have a timesheet template with date values (properly formatted to serial #) in column range F8:NG8 and drop-down list to select "view" month of "Jan", "Feb", "Mar", etc. in cell A5.
When user selects "Jan" from drop-down, I want all columns in range F8:NG8 with date NOT in January to be hidden and likewise for each month selected.
I know this isn't super complicated yet I can't seem to get the code right. I have had success with the following code assigned to buttons to show current day/week/month (included month code below) which most users will use but just in case they want to view a one month period that is NOT the current month I have the drop-down selection option. How do I adjust this with "IF" arguments dependent upon drop-down? I also welcome any other more efficient suggestions.
Sub ShowMonth()
Dim MyRange As Range, c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set MyRange = Range("F$8:NG$8")
MyRange.EntireColumn.Hidden = True
For Each c In MyRange
If Month(c.Value) = Month(Date) Then
c.EntireColumn.Hidden = False
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
I have a timesheet template with date values (properly formatted to serial #) in column range F8:NG8 and drop-down list to select "view" month of "Jan", "Feb", "Mar", etc. in cell A5.
When user selects "Jan" from drop-down, I want all columns in range F8:NG8 with date NOT in January to be hidden and likewise for each month selected.
I know this isn't super complicated yet I can't seem to get the code right. I have had success with the following code assigned to buttons to show current day/week/month (included month code below) which most users will use but just in case they want to view a one month period that is NOT the current month I have the drop-down selection option. How do I adjust this with "IF" arguments dependent upon drop-down? I also welcome any other more efficient suggestions.
Sub ShowMonth()
Dim MyRange As Range, c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set MyRange = Range("F$8:NG$8")
MyRange.EntireColumn.Hidden = True
For Each c In MyRange
If Month(c.Value) = Month(Date) Then
c.EntireColumn.Hidden = False
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub