I've tried using the code below, in various formats as you can see from the commented out code, to try and find the address of the cell in the first row which contains the current month of the year.
All the months in the first row display as 'January - 2020', 'February - 2020' etc.
However, the code always displays the date of the cell with 'December - 2020' in it and not February as you'd expect. Now I'm sure it is an issue to do with the way that date/time is stored but I'm at a loss as to how to fix this issue.
Any help is appreciated. Thanks
VBA Code:
Private Sub Find_test()
Dim dteTodaysMonth As Date
dteTodaysMonth = Format(Now, "mmmm - yyyy")
'dteTodaysMonth = DateSerial(Format(Now, "yyyy"), Format(Now, "mm"), 1)
With Worksheets("Sheet1").Rows(1)
'Debug.Print .Find(What:=dteTodaysMonth, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Address
'Debug.Print .Find(What:=DateValue(dteTodaysMonth), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Address
Debug.Print .Find(What:=DateSerial(Format(Now, "yyyy"), Format(Now, "mm"), 1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Address
End With
End Sub
All the months in the first row display as 'January - 2020', 'February - 2020' etc.
However, the code always displays the date of the cell with 'December - 2020' in it and not February as you'd expect. Now I'm sure it is an issue to do with the way that date/time is stored but I'm at a loss as to how to fix this issue.
Any help is appreciated. Thanks