Keep a 24-Hour Time Format After VBA Text to Columns in Excel
Question details
Keep the time displayed in 24-hour format after splitting a date-time value with VBA Text to Columns.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA macro splits space-separated date and time values into separate worksheet columns.
- Observed behavior
- The split time may display with AM or PM because the destination column uses a 12-hour number format, even though the value is a valid Excel time.
Check that the source cells contain date and time text separated by a space, and identify the source date order. Make sure the destination columns are empty or do not contain data you need, because Text to Columns can overwrite them.
Set the destination time format in the VBA macro
Use this approach to split the date and time and automatically display the resulting time in 24-hour format.
The example reads column U, places the date in column V and the time in column W, and assumes the source date is in day-month-year order. Change the ranges and date format if your data is different.
In Excel, open the Developer tab and select Visual Basic. In the VBA editor, select Insert > Module.
Paste the following code into the module: Sub SplitDateTime24Hour() Range("U:U").TextToColumns Destination:=Range("V1"), _ DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True, _ FieldInfo:=Array(Array(1, xlDMYFormat), Array(2, xlGeneralFormat)) Columns("W:W").NumberFormat = "hh:mm" End Sub
In the FieldInfo argument, replace xlDMYFormat with xlMDYFormat for month-day-year dates or xlYMDFormat for year-month-day dates. Leave the second field as xlGeneralFormat so Excel can interpret the time.
Return to the worksheet containing the data, open Developer > Macros, select SplitDateTime24Hour, and click Run. Check that column W displays times such as 19:09.

Apply a 24-hour format to the split time column
Use this option if the split is already complete and the destination cells contain valid Excel time values.
Work with 24-hour times in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files, format time cells, and move between office tools with ease; it does not fix Excel's VBA behavior.

Frequently Asked Questions
Why does Excel show AM or PM after Text to Columns?
The destination cells may have a 12-hour number format. Select the time cells and use Format Cells > Number > Custom with hh:mm to display valid time values in 24-hour notation.
What is the difference between hh:mm and [h]:mm?
Use hh:mm for clock times, such as 19:09. Use [h]:mm for elapsed durations when the total hours can exceed 24.
Which VBA date format should I use in FieldInfo?
Match the format to the source text: use xlDMYFormat for day-month-year, xlMDYFormat for month-day-year, or xlYMDFormat for year-month-day.
Why does changing the number format leave the time unchanged?
The cell may contain text instead of a numeric Excel time. Check the split results, then rerun Text to Columns with the time field set to General and apply the hh:mm format.




