VBA & Macro Problems

How to Convert Text to Dates with Excel VBA

Rana GarciaRana Garcia Nov 10, 2026 871 views

Question details

The user needs to convert text-formatted dates (such as 'MAR 23 2025' or '23/03/2025') in a specific column into valid Excel serial dates using VBA.

How to Convert Text to Dates with Excel VBA
Product
Excel
Device & OS
not provided
Scenario
Cleaning up imported or manually entered data where dates are stored as text strings, making them unusable for chronological sorting or date arithmetic.
Observed behavior
Dates are stored as text and are not recognized by Excel as valid date values, requiring a programmatic way to parse and convert them while preserving already valid dates.
Before you start

Ensure you have saved a backup copy of your workbook, and verify that the text dates you want to convert are consistently located in a specific column (like Column D) before running the macro.

Solution 1Recommended

Use a VBA Macro to Parse and Convert Text Dates

Use a custom VBA script to loop through your target column, identify text cells, and convert them safely using the Split, DateValue, and DateSerial functions.

This approach loops through the specified range (e.g., Column D) and checks if the cell contains text. Depending on the delimiter format—whether separated by spaces ('MAR 23 2025') or slashes ('23/03/2025')—it parses the string and reconstructs a proper Excel date to avoid regional settings conflicts.

1
Open the VBA Editor

In your open Excel workbook, press 'Alt + F11' on your keyboard to launch the Microsoft Visual Basic for Applications editor.

2
Insert a New Module

Click on 'Insert' in the top menu bar and select 'Module' to create a blank script window.

3
Paste the VBA Code

Copy and paste the following code into the module window: Sub ConvertDates() Dim rng As Range Dim parts() As String Application.ScreenUpdating = False For Each rng In Range(Range("D2"), Range("D" & Rows.Count).End(xlUp)) If Application.IsText(rng.Value) Then parts = Split(rng.Value) If UBound(parts) > 0 Then rng.Value = DateValue(parts(1) & "-" & parts(0) & "-" & parts(2)) Else parts = Split(rng.Value, "/") If UBound(parts) > 0 Then rng.Value = DateSerial(parts(2), parts(1), parts(0)) End If End If End If Next rng Application.ScreenUpdating = True End Sub

4
Run the Macro

Close the VBA Editor, return to your worksheet, press 'Alt + F8', select 'ConvertDates' from the Macro dialog box, and click 'Run'.

Using DateSerial for Accuracy: Using DateSerial(Year, Month, Day) is highly recommended for slash-separated dates (like dd/mm/yyyy) because it prevents Excel from accidentally swapping days and months based on your computer's regional settings.

Process and Analyze Data Efficiently with WPS Office

WPS Spreadsheet provides powerful data processing tools, including built-in Text to Columns and robust VBA/Macro support, allowing you to easily convert and manage complex date formats.

  1. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open the workbook containing your text dates.
  2. 2. Access the Developer Tools: Go to the 'Tools' tab and click on 'Developer' to access the VBA editor where you can run your date conversion macro.
  3. 3. Use Text to Columns: Alternatively, select your dates, navigate to the 'Data' tab, and use 'Text to Columns' to quickly parse dates without any coding required.
Seamless compatibility with Microsoft Excel formats (.xlsx, .xls, .csv).Advanced VBA and Macro support in premium versions for automated data cleaning.Intuitive UI with powerful built-in data processing features like Text to Columns.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't Excel recognize my dates automatically?

Excel relies on your system's regional settings to interpret dates. If the imported text date format (like dd/mm/yyyy) differs from your system's default setting (like mm/dd/yyyy), Excel fails to parse it and treats it as a simple text string.

Can I convert text dates without using VBA?

Yes, you can use the 'Text to Columns' feature under the Data tab. Alternatively, you can use formulas like DATEVALUE() combined with text manipulation functions (LEFT, MID, RIGHT) to parse the text into a valid date structure.

What does the CDate function do in VBA?

The CDate function converts a valid string expression into a Date data type. However, it relies heavily on your computer's locale settings, which is why explicit parsing using DateSerial is often a safer choice for irregular or non-standard date formats.