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 16, 2026

Question posted 2012 · +8 upvotes

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"

Accepted answer +18 upvotes

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

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

VBA Core objects referenced (4)

  • Range — Refer to Cells by Using a Range Object
  • Range — Delete Duplicate Entries in a Range
  • TextBox3.Value — Cell Error Values
  • TextBox3.Value — Fill a Value Down into Blank Cells in a Column

Top vba Q&A (6)

+18 upvotes ranks this answer #20 out of 81 vba solutions on this site — top 25%.
vba