docs / articles / VBA: Select Date from Calendar

VBA: Select Date from Calendar

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

When working with VBA (Visual Basic for Applications) in Excel, selecting a date from a calendar is a common task. This functionality is not built-in, but it can be achieved using various methods and libraries. In this article, we'll explore how to select a date from a calendar in VBA, step by step.

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

Before we dive into the code, let's understand why you might need to select a date from a calendar. This could be useful in scenarios where you want to input a date for a specific task, like scheduling an event, setting a deadline, or filtering data based on a date range.

Sort Data by Date in VBA
Sort Data by Date in VBA

Using the InputBox Function

The InputBox function is a simple way to select a date from a calendar in VBA. It displays a dialog box where users can input a date.

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

Here's a basic example of how to use the InputBox function to select a date:

Basic InputBox Example

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

First, let's create a simple VBA subroutine that uses the InputBox function to select a date:

Sub SelectDateUsingInputBox()
    Dim userDate As Variant
    userDate = InputBox("Select a date", "Date Picker", Date) ' Defaults to today's date
    If IsDate(userDate) Then
        MsgBox "You selected: " & userDate
    Else
        MsgBox "Invalid date selected."
    End If
End Sub

This code displays an InputBox with a calendar icon, allowing users to select a date. The selected date is then displayed in a message box.

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

Customizing the InputBox

While the basic InputBox function works, it has some limitations. For instance, it doesn't allow you to set a minimum or maximum date, or customize the calendar's appearance.

To overcome these limitations, you can use a third-party library like the VBA-Calendar add-in. This add-in provides a customizable date picker control that you can use in your VBA projects.

Excel VBA Basics #25 Extract the DAY, WEEKDAY, MONTH, YEAR from a date. How to use DateSerial
Excel VBA Basics #25 Extract the DAY, WEEKDAY, MONTH, YEAR from a date. How to use DateSerial

Using the VBA-Calendar Add-In

The VBA-Calendar add-in offers a more robust solution for selecting a date from a calendar in VBA. It provides a user-friendly interface with customizable options.

Excel VBA: First Day of Month (3 Methods)
Excel VBA: First Day of Month (3 Methods)
Calculate days from/before date in Excel
Calculate days from/before date in Excel
Excel VBA UserForm with Navigation Buttons | Move Between Records Easily!
Excel VBA UserForm with Navigation Buttons | Move Between Records Easily!
Automate Data Entry Like a Pro with VBA in Access
Automate Data Entry Like a Pro with VBA in Access
How I Master My Calendar on Buffer's Distributed Team
How I Master My Calendar on Buffer's Distributed Team
a calendar with buttons on it and the date for each month in different colors, sizes and
a calendar with buttons on it and the date for each month in different colors, sizes and
Create a date sequence in Excel and auto fill date series
Create a date sequence in Excel and auto fill date series
Dynamic Calendar with Single formula connected with Task List || No VBA Used
Dynamic Calendar with Single formula connected with Task List || No VBA Used
three calendars are shown with the same date as each month, and one is empty
three calendars are shown with the same date as each month, and one is empty
Use This Free Excel Date Picker to Enter Dates on Worksheet
Use This Free Excel Date Picker to Enter Dates on Worksheet
Excel Tips and Tricks in Excel | Get date difference from Date | Excel Tutorials in Hindi | Excel
Excel Tips and Tricks in Excel | Get date difference from Date | Excel Tutorials in Hindi | Excel
NEW Date Picker in Excel for Web – Finally Here
NEW Date Picker in Excel for Web – Finally Here
How to fill date by week in Excel quickly and easily?
How to fill date by week in Excel quickly and easily?
Calendar — Select Date
Calendar — Select Date
an iphone calendar with the date and time in pink, black and gold colors on it
an iphone calendar with the date and time in pink, black and gold colors on it
Effective Calendars You Can Edit
Effective Calendars You Can Edit
The only customizable calendar for business - Teamup Home
The only customizable calendar for business - Teamup Home
an image of a calendar in microsoft office 365
an image of a calendar in microsoft office 365
date picker inspiration
date picker inspiration
a calendar with the dates and times for each school in english, spanish and chinese
a calendar with the dates and times for each school in english, spanish and chinese

Here's how to use the VBA-Calendar add-in:

Installing the VBA-Calendar Add-In

First, you need to install the VBA-Calendar add-in. You can download it from the VBA-Tools website. Once downloaded, extract the files and follow the installation instructions.

Using the VBA-Calendar in Your VBA Project

After installation, you can use the VBA-Calendar in your VBA project. Here's an example of how to use it:

Sub SelectDateUsingVBA_Calendar()
    Dim userDate As Variant
    userDate = Calendar ' This line displays the calendar and returns the selected date
    If IsDate(userDate) Then
        MsgBox "You selected: " & userDate
    Else
        MsgBox "No date selected."
    End If
End Sub

This code displays the VBA-Calendar dialog box, allowing users to select a date. The selected date is then displayed in a message box.

In conclusion, selecting a date from a calendar in VBA can be achieved using the InputBox function or third-party libraries like the VBA-Calendar add-in. Each method has its pros and cons, so the choice depends on your specific needs. Happy coding!