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

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
63
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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
I found this on another thread, and it did the job:

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

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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
Back
Top