docs / articles / Excel VBA: Select Date from Calendar

Excel VBA: Select Date from Calendar

Eric Jul 09, 2026 2026-07-09 04:40:47

Mastering Excel VBA for date manipulation can significantly enhance your productivity. One common task is selecting dates from a calendar. Let's delve into how you can achieve this efficiently using VBA.

Excel VBA USERFORMS #25 Date Picker Calendar revealed! Loop through Userforms and Controls  Example
Excel VBA USERFORMS #25 Date Picker Calendar revealed! Loop through Userforms and Controls Example

VBA, or Visual Basic for Applications, is a powerful tool embedded within Excel that allows you to automate tasks, manipulate data, and create custom functions. By learning how to select dates from a calendar using VBA, you can streamline your workflow and save time.

an image of a calendar in microsoft office 365 with the date and time tab open
an image of a calendar in microsoft office 365 with the date and time tab open

Understanding the Excel Calendar

Before we dive into VBA, it's crucial to understand how Excel represents dates. Excel stores dates as serial numbers, where 1 represents January 1, 1900. Each day after that is represented by a sequential number. This system allows us to perform calculations and manipulations on dates easily.

Free Excel Calendar Template
Free Excel Calendar Template

Excel's built-in calendar is a user-friendly interface that displays dates in a month view. It's located in the 'Date & Time' category of the Insert tab. Understanding how to navigate and interact with this calendar will help you in using VBA to select dates.

Selecting a Single Date

How to insert dates from a Popup Calendar (date picker) in Excel – user guide | XLTools
How to insert dates from a Popup Calendar (date picker) in Excel – user guide | XLTools

To select a single date using VBA, you can use the 'InputBox' function. This function displays a dialog box where the user can input a date. Here's a simple example:

Sub SelectDate()
Dim userDate As Variant
userDate = InputBox("Select a date", "Date Selection", Date)
If IsDate(userDate) Then
MsgBox "You selected: " & userDate
End If
End Sub

Selecting a Range of Dates

Excel VBA UserForm with Navigation Buttons 🚀 | See it in Action! #shorts
Excel VBA UserForm with Navigation Buttons 🚀 | See it in Action! #shorts

Selecting a range of dates is a bit more complex, as it involves looping through the dates and using the 'Range' object to select them. Here's an example of selecting all dates in a month:

Sub SelectMonthDates()
Dim startDate As Date
Dim endDate As Date
Dim currentDate As Date
Dim cell As Range
startDate = DateSerial(Year(Date), Month(Date), 1)
endDate = DateSerial(Year(Date), Month(Date) + 1, 1)
Set cell = Range("A1") 'Assuming you want to start selecting dates from cell A1'
For currentDate = startDate To endDate - 1
cell.Value = currentDate
cell.Offset(0, 1).Select
Next currentDate
End Sub

Interacting with the Excel Calendar Using VBA

How to create a drop down list calendar (date picker) in Excel?
How to create a drop down list calendar (date picker) in Excel?

Excel's calendar can be manipulated using VBA to select dates. The 'Calendar' object is not built into Excel, so you'll need to create a UserForm with a Calendar control. Here's a basic example:

Private Sub Calendar1_Change()
Dim selectedDate As Date
selectedDate = Calendar1.Value
MsgBox "You selected: " & selectedDate
End Sub

FREE Calendar & Planner Excel Template for 2026
FREE Calendar & Planner Excel Template for 2026
Calender in Excel ‼️ Amazing Excel trick using data validation and conditional formatting ✅ #Excel
Calender in Excel ‼️ Amazing Excel trick using data validation and conditional formatting ✅ #Excel
a calendar with the word january on it
a calendar with the word january on it
NEW Date Picker in Excel for Web – Finally Here
NEW Date Picker in Excel for Web – Finally Here
How to Insert a Calendar in Excel (the Simplest Way)
How to Insert a Calendar in Excel (the Simplest Way)
Excel Date Picker Tool - Contextures Blog
Excel Date Picker Tool - Contextures Blog
Use This Free Excel Date Picker to Enter Dates on Worksheet
Use This Free Excel Date Picker to Enter Dates on Worksheet
Create a date sequence in Excel and auto fill date series
Create a date sequence in Excel and auto fill date series
Excel VBA UserForm with Navigation Buttons | Move Between Records Easily!
Excel VBA UserForm with Navigation Buttons | Move Between Records Easily!
Calendar in Excel: Make Dynamic, Interactive Calendar in Excel with Formula + Conditional Formatting
Calendar in Excel: Make Dynamic, Interactive Calendar in Excel with Formula + Conditional Formatting
Create a Calendar in Microsoft Excel or Insert a Reference Calendar
Create a Calendar in Microsoft Excel or Insert a Reference Calendar
Excel VBA Copy Data from Multiple Workbooks
Excel VBA Copy Data from Multiple Workbooks
Excel Calendar 2025 with 25 designed layouts - Free Download
Excel Calendar 2025 with 25 designed layouts - Free Download
Excel VBA: Insert Data into Table (4 Examples)
Excel VBA: Insert Data into Table (4 Examples)
Don't save the date 📆
Don't save the date 📆
Effective Calendars You Can Edit
Effective Calendars You Can Edit
the excel time and date sheet
the excel time and date sheet
What You Can Do with VBA (6 Practical Uses)
What You Can Do with VBA (6 Practical Uses)

In this example, the 'Calendar1_Change' event is triggered whenever a date is selected in the calendar. The selected date is then displayed in a message box.

Using the 'Application.InputBox' Method

Another way to select dates using VBA is by using the 'Application.InputBox' method. This method displays a customizable dialog box where the user can select a date. Here's an example:

Sub SelectDateUsingInputBox()
Dim userDate As Variant
userDate = Application.InputBox("Select a date", Type:=2)
If IsDate(userDate) Then
MsgBox "You selected: " & userDate
End If
End Sub

The 'Type:=2' argument in the 'InputBox' method specifies that the input should be a date.

Remember, practice makes perfect. The more you work with VBA, the more comfortable you'll become with selecting dates and performing other tasks. Don't be afraid to experiment and make mistakes - that's how you'll learn and improve.

Happy automating!