VBA Function: CDate

The VBA function CDate converts a value to a date, when that value can be considered a date.

Usage:

CDate(value)


Example of Usage

Using the CDate function to convert the value entered in the TextBox field to a date:

excel vba userform textbox cdate

The following event is triggered when clicking the Submit button, it converts the date (in text format) from the field to a date and enters it into cell A1:

Private Sub CommandButton_submit_Click()

    Range("A1") = CDate(TextBox_date)

End Sub
excel vba userform textbox date cell cdate
To avoid getting an error if the value cannot be converted to a date, you can test the value using the IsDate function.