I have a calendar in my spreadsheet that returns a date selected to a cell that is active.
When the user clicks cell D40 in worksheet Surcharges, I use a Worksheet_SelectionChange event to show the calendar. When the user selects a date it returns the date in that cell.
Problem is I want to limit the user to select a date no more than 90 days from today's date.
I was having a problem using today() in the vba code.
When i enter todays date in cell E39 (-today()) and use the code below it works:
Private Sub Calendar1_Click() ActiveCell.Value = Calendar1.Value Unload Me If Calendar1.Value - Range("e39").Value > 90 Then MsgBox "over 90!" Range("d40").Value = "" Exit Sub End If End Sub
But when I try to use the today() function below I get errors:
Private Sub Calendar1_Click() Dim x As Date ActiveCell.Value = Calendar1.Value Unload Me x = date(today()) If Calendar1.Value - x > 90 Then MsgBox "over 90!" Range("d40").Value = "" Exit Sub End If End Sub
What am I doing wrong? I would prefer to avoid putting =today() in a cell and refer to it. Is that even possible?