VBA & Macro Problems

Write a Selected Calendar Date to an Excel Cell

Chanuka GeekiyanageChanuka Geekiyanage Dec 2, 2026 868 views

Question details

Write a date selected in an Excel calendar to a specific worksheet cell.

Write a Selected Calendar Date to an Excel Cell
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user selects a date in a calendar control and clicks a button to place it on a worksheet.
Observed behavior
The calendar displays dates, but the selected date is not written to the worksheet.
Before you start

Identify the calendar’s confirmation button, the worksheet and target cell, and the variable or control property that holds the selected date. Open the workbook in a version of Excel that supports its VBA calendar control.

Solution 1Recommended

Assign the selected date in the calendar button’s click event

Use VBA to write the date to a worksheet cell when the user clicks the calendar’s button.

The example assumes selectedDate already contains the chosen date and is accessible to the button’s event procedure. The way you obtain that value depends on the calendar control.

1
Open the button’s event procedure

In Excel, select Developer > Visual Basic. In the VBA editor, open the calendar’s form and double-click its confirmation button to open the Click event.

2
Write the date to the cell

Inside the button’s Click procedure, add: ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = selectedDate. Replace Sheet1 and A1 with your worksheet and target cell, and replace selectedDate with the variable or expression that holds the selected date.

3
Save and test the calendar

Use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Reopen it, enable macros if prompted and appropriate, select a date, and click the calendar button to check the target cell.

Assign the selected date in the calendar button’s click event
Check the date value: If the cell remains blank or VBA reports an error, check that the button’s Click event runs and that the selected date is available in that procedure before the assignment.
Free Microsoft Office alternative

Enter and manage worksheet dates with WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and enter dates directly in cells for a straightforward move to WPS. The Excel VBA calendar control and its button event may not work the same way in WPS.

Enter and format dates directly in worksheet cellsCompatible with Microsoft Excel formats such as XLSXFamiliar spreadsheet interface for an easier transitionFree and lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

How do I write the date to a different cell?

In the button’s Click event, change ThisWorkbook.Worksheets("Sheet1").Range("A1") to the worksheet name and cell address you want to use.

Where does selectedDate come from?

It represents the date chosen in your calendar. Use the variable or control property supplied by your calendar implementation, and make sure its value is accessible inside the button’s Click procedure.

Why does the cell show a number instead of a date?

Excel stores dates as serial numbers. Select the target cell, open Home > Number Format, and choose a date format.

Which file format preserves the VBA code?

Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). A standard .xlsx file does not preserve VBA macros.