I am using a calendar userform for the first time and things are going well except the value that gets written to a cell.
Initially I had this:
The above is writing what looks like a date value to the cell, but it's formatting can't be modified and simply trying Range("H10") + 1 results in a value error. So it looks like a date but it's not recognized as a date. It seems to be just text.
So I then tried:
But it's resulting in the same thing. However, I put a watch on my code and in the immediate window doing: print cal_date + 1 results in the selected date + 1 day. So obviously it's a date but somehow it's not being written to the sheet as such. I cleared that cell (H10) and manually typed in a date and verified it was behaving as a date, but then running the calendar userform results in it writing an invalid date again.
What am I missing?
Initially I had this:
Code:
Private Sub Calendar1_Click()
Sheets("options menu").Range("H10") = Calendar1.Value
The above is writing what looks like a date value to the cell, but it's formatting can't be modified and simply trying Range("H10") + 1 results in a value error. So it looks like a date but it's not recognized as a date. It seems to be just text.
So I then tried:
Code:
cal_month = Month(Calendar1.Value)
cal_year = Year(Calendar1.Value)
cal_day = Day(Calendar1.Value)
cal_date = DateSerial(cal_year, cal_month, cal_day)
Sheets("options menu").Range("H10") = cal_date
But it's resulting in the same thing. However, I put a watch on my code and in the immediate window doing: print cal_date + 1 results in the selected date + 1 day. So obviously it's a date but somehow it's not being written to the sheet as such. I cleared that cell (H10) and manually typed in a date and verified it was behaving as a date, but then running the calendar userform results in it writing an invalid date again.
What am I missing?