VBA code to set date format for a specific column as “yyyy-mm-dd”

calendar_today Asked Sep 7, 2012
thumb_up 18 upvotes
history Updated April 14, 2026

Direct Answer

Use the range's NumberFormat property to force the format of the range like this: Sheet1.Range("A2", "A50000").NumberFormat = "yyyy-mm-dd". This is a prose walkthrough, ranked #29th of 95 by community upvote score, from 2012.


The Problem (Q-score 8, ranked #29th of 95 in the VBA Core archive)

The scenario as originally posted in 2012

I have a macro which I specify the date (in mm/dd/yyyy) in a textbox and I want to set this value for column A in yyyy-mm-dd format. I have the following code:

Sheets("Sheet1").Range("A2", "A50000").Value = TextBox3.Value
Sheet1.Range("A2", "A50000") = Format(Date, "yyyy-mm-dd")

…and when I run the macro, the date is still in mm/dd/yyyy format.

How can I change this so that it is in the format I want?? I’ve been trying many kinds of code researched through google and nothing will set the format the way I want it.

Any help will be appreciated…

EDIT: Full code from OP’s comment below:

 Workbooks.Add
 Range("A1") = "Acctdate"
 Range("B1") = "Ledger"
 Range("C1") = "CY"
 Range("D1") = "BusinessUnit"
 Range("E1") = "OperatingUnit"
 Range("F1") = "LOB"
 Range("G1") = "Account"
 Range("H1") = "TreatyCode"
 Range("I1") = "Amount"
 Range("J1") = "TransactionCurrency"
 Range("K1") = "USDEquivalentAmount"
 Range("L1") = "KeyCol"
 Sheets("Sheet1").Range("A2", "A50000").Value = TextBox3.Value
 Sheet1.Range("A2", "A50000").NumberFormat = "yyyy-mm-dd"

Why this Range / Worksheet targeting trips people up

The question centers on reaching a specific cell, range, or workbook object. In VBA Core, this is the #1 source of failures after activation events: every property (.Value, .Formula, .Address) behaves differently depending on whether the parent Workbook is explicit or implicit.


The Verified Solution — strong answer (top 25 %%) (+18)

Verbal answer — walkthrough without a code block

Note: the verified answer is a prose walkthrough. If you need a runnable sample, check VBA Core entries ranked in the top 10 of the same archive.

Use the range’s NumberFormat property to force the format of the range like this:

Sheet1.Range("A2", "A50000").NumberFormat = "yyyy-mm-dd"


When to Use It — vintage (14+ years old, pre-2013)

Ranked #29th in its category — specialized fit

This pattern sits in the 85% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.

What changed between 2012 and 2026

The answer is 14 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why does this sit in the top quartile of VBA Core answers?
expand_more

Answer score +18 vs the VBA Core archive median ~6; this entry is strong. The score plus 8 supporting upvotes on the question itself (+8) means the asker and 17 subsequent voters all validated the approach.

The answer has no code block — how do I turn it into a snippet?
expand_more

Use the walkthrough above as a checklist, then open a top-10 VBA Core archive entry for a concrete starting template you can adapt.

This answer is 14 years old. Is it still relevant in 2026?
expand_more

Published 2012, which is 14 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #28?
expand_more

The pattern one rank above is “Using VBA to get extended file attributes”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 8, Answer-score 18, original post 2012, ranked #29th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba