formatting a form to display date as yyyy-mm-dd

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
61
I have a form allows the user to enter a date, then writes that date to cell E3
If there is already a date in cell E3, I pre-populate my form with this date (so the user doesn't have to enter it again). When I do this, the format is always wrong
I want the format to be yyyy-mm-dd, but when I read the existing date in cell E3, it shows up in my form as mm/dd/yyyy
Is there a way I can format my form to always show dates as yyyy-mm-dd

If Worksheets("Quotation").Range("E3") <> "" Then
QuotationForm.Quote_Date.Value = Worksheets("Quotation").Range("E3") 'when I read in the date from cell E3, it's always formatting as mm/dd/yyyy...I want it to be yyyy-mm-dd
Else
TodayDate = Format(Date, "yyyy-mm-dd")
QuotationForm.Quote_Date.Value = TodayDate
End If
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,518
Office Version
  1. 2019
Platform
  1. Windows
Hi,
try this update to your code & see if does what you want

VBA Code:
    With Worksheets("Quotation").Range("E3")
        Me.Quote_Date.Value = IIf(IsDate(.Text), .Text, Format(Date, "yyyy-mm-dd"))
    End With

Dave
 

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
61
I found this on another thread, and it did the job:

QuotationForm.Quote_Date.Value = Format(Worksheets("Quotation").Range("E3"), "yyyy-mm-dd")
 

Watch MrExcel Video

Forum statistics

Threads
1,129,970
Messages
5,639,317
Members
417,081
Latest member
Jeyaraj2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top