Slizer6893
Active Member
- Joined
- Oct 25, 2013
- Messages
- 271
Code:
Private Sub worksheet_Selectionchange(ByVal target As Range)Dim c As Range
Dim mycellschanged As Range
Dim mydatecells As Range
Dim CurrentDate As Range
Set mycellschanged = Intersect(target, Range("A2"))
Set mydatecells = Range("BJ5:CG5")
Set CurrentDate = Range("A2")
If mycellschanged Is Nothing Then Exit Sub
CurrentDate.Value = Month(CurrentDate.Value)
For Each c In mydatecells
If c.Value >= CurrentDate Then
c.EntireColumn.Hidden = True
Else
c.EntireColumn.Hidden = False
End If
Next c
End Sub
At the moment this code isn't doing what I need it to. I have tweaked it a few times and I am having a few issues.
-A2 is going to be a drop down list that will specify date : Lets just say its months only not an actual date value that I know of
-BJ-CG are where months are across the top (So the most recent one would be September but months after, are still showing)
The goals: If my user changes the date in the drop down then all dates that are after that within my range will stay hidden (This allows my YTD column to automatically pull closer to the most recent month). Each month they can change the date and the new columns will appear.
My biggest issue is that using a data validation with dates doesn't seem to see September as greater than or equal to September since its using date values. (I do not want to change my headers) Can anyone think of a way that I can have it look at it like a month value instead? Month(Currentdate.value) didn't work?