VBA & Macro Problems

Keep Excel VBA Date Values as Text in yyyy-mm-dd Format

Ayan MasoodAyan Masood Dec 2, 2026 868 views

Question details

Convert Excel dates into yyyy-mm-dd text strings that another program can read.

Keep Excel VBA Date Values as Text in yyyy-mm-dd Format
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11, select the workbook in the Project pane, and choose Insert > Module.

2
Add the conversion macro

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

3
Run and verify

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 Excel dates to text with VBA
Check the stored value: In an empty cell, use =ISTEXT(G2) to confirm that the converted value is text. A date-looking display alone does not confirm its storage type.
Convert dates in WPS Spreadsheet

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. 1. Open the workbook: Open WPS Spreadsheet and use Open to select the Excel workbook containing the dates.
  2. 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. 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. 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.
Convert date values into yyyy-mm-dd text stringsOpen and save Microsoft Excel formats such as XLSXUse familiar spreadsheet formulas and number formatsWork with a free, easy-to-use office suite
microsoft office alternative - wps office

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.