Keep Excel VBA Date Values as Text in yyyy-mm-dd Format
Question details
Convert Excel dates into yyyy-mm-dd text strings that another program can read.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA macro prepares date values for a program that requires text rather than Excel date serial numbers.
- Observed behavior
- A custom date format displays the expected pattern, but the underlying values remain date serial numbers, and the format appears to change after the workbook is reopened.
Identify the source date column and an empty destination column. Confirm that the source cells contain Excel date values rather than existing text, and enable macros only if you trust the workbook.
Convert Excel dates to text with VBA
Use this method when the conversion needs to run as part of a macro.
A custom number format changes only how a date serial is displayed. The macro must write a text string to the destination cell.
This example reads dates from column F and writes text to column G on the active worksheet. It skips blank source cells and assumes nonblank source cells contain valid Excel date serials. Change the columns if needed; existing values in the destination range will be overwritten.
In Excel, press Alt+F11, select the workbook in the Project pane, and choose Insert > Module.
Paste this code into the module: Sub DatesToText() Dim ws As Worksheet Dim lastRow As Long Dim c As Range Set ws = ActiveSheet lastRow = ws.Cells(ws.Rows.Count, "F").End(xlUp).Row If lastRow < 2 Then Exit Sub ws.Range("G2:G" & lastRow).NumberFormat = "@" For Each c In ws.Range("F2:F" & lastRow) If Not IsEmpty(c.Value2) Then ws.Cells(c.Row, "G").Value = Application.WorksheetFunction.Text(c.Value2, "yyyy-mm-dd") End If Next c End Sub
Activate the intended worksheet, press Alt+F8, select DatesToText, and click Run. Check column G, then save and reopen the workbook and verify that the destination values remain text.

Convert dates with a formula and paste text values
Use this method for a one-time conversion without writing VBA.
Check code and processes that change the workbook
Use this check if the destination format or values change after saving or reopening.
Create yyyy-mm-dd text values in WPS Spreadsheet
Use the TEXT function and paste its results as values to prepare date strings for another program in WPS Spreadsheet.
- 1. Open the workbook: Open WPS Spreadsheet and use Open to select the Excel workbook containing the dates.
- 2. Create the text strings: In an empty General-formatted cell such as G2, enter =TEXT(F2,"yyyy-mm-dd") and fill it down.
- 3. Set the destination to text: Select an empty destination column such as H and choose Text from the number format options on the Home tab.
- 4. Paste and verify the values: Copy the formula results, select H2, and use Paste Special > Values. Enter =ISTEXT(H2) in an empty cell to check that the result is text.

Frequently Asked Questions
Why does a yyyy-mm-dd number format not make a date text?
A custom number format controls display only; the underlying Excel date remains a serial number. Use =TEXT(F2,"yyyy-mm-dd") to create a string.
How can I check whether a converted date is stored as text?
Enter =ISTEXT(G2) in an empty cell, replacing G2 with the destination cell. TRUE means the value is text.
Why did my TEXT formula appear instead of calculating?
The formula may have been entered into a Text-formatted cell. Change the formula cell to General, re-enter the formula, and paste the calculated result as a value into a separate Text-formatted destination.
What could change the format when I reopen the workbook?
Check Workbook_Open and Workbook_BeforeClose in the VBA editor, as well as other macros, table operations, and external programs that modify the workbook.




