(Excel 2010 VBA) I have a cell (A1) containing a date in the format of mmm-yy ("Custom" category). Foe example, if I enter 1/6/13 the cell shows June-13. That's fine. In my VB macro I need to check this date whether the month is the current month and whether the year is the current year. I don't care about the day.
3 Answers
5
votes
2
votes
1
votes
How about this:
Function MonthYear() As Boolean
MonthYear = False
If Not IsDate(Cells(1, 1)) Then Exit Function
If Month(Date) = Month(Cells(1, 1)) And Year(Date) = Year(Cells(1, 1)) Then
MonthYear = True
End If
End Function
The function returns true if month and year are the same as current date. If not it returns false.