I am working on my first VBA project and I am really stuck.
On my Excel sheet I need a Date Picker. The Excel version I am using does not have one, so I created my own calendar using the code from the link below ( The one created by L42, with the 42 labels and so on):
Formatting MM/DD/YYYY dates in textbox in VBA
The calendar looks just like the one in the image, so all good so far.
On my Excel spreadsheet I added a code which makes the calendar pop up only in two cells, E2 and F2, which represent the start date and the end date for my data.
Private Sub worksheet_selectionchange(ByVal target As Range)
If Not Application.Intersect(Range("E2"), target) Is Nothing Then
MyCalendar.Show
End If
If Not Application.Intersect(Range("F2"), target) Is Nothing Then
MyCalendar.Show
End If
End Sub
Everything works fine, the calendar only pops up when I click on these two cells only. So, when I click on E2, the calendar pops up, I select a date, then a message box with the selected date pops up, I click ok to close it, then I close the calendar, but the date I clicked on will not be inserted in my E2 cell.
I guess I need a code in the select_label procedure below which will make the date I click on in the calendar and pops up in the MsgBox actually fill my excel E2 or F2 cells.
Private Sub select_label(msForm_C As MSForms.Control)
'/* Capture the selected date */
Dim i As Integer, sel_date As Date
i = Split(msForm_C.Name, "_")(1) - 1
sel_date = FirstCalSun(curMonth) + i
'/* Transfer the date where you want it to go */
MsgBox sel_date
End Sub
Any help is much appreciated.
Thank you.