Hello

Users need to be able to enter a date into a TextBox on a UserForm in the Format DD-MM-YYYY.

This is then converted once entered into the format YYYY-MM-DD and when the SAVE button is selected, this is written to the spreadsheet.

The issue I am having is that the value written to the spreadsheet does not return the date in the required format of YYYY-MM-DD.

My code is below:

Code to check if DOB completed:
If Trim(DOBText.Text) = "" Then
             DOBText.SetFocus
             MsgBox "Please enter a Date of Birth in the format dd/mm/yyyy", vbCritical, "Input Required"
             Exit Sub
         End If
Code to convert entered date to YYYY-MM-DD format
Private Sub DOBText_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not IsDate(DOBText) Then
        DOBText.SetFocus
        MsgBox "Please enter a Date of Birth in the format dd/mm/yyyy", vbCritical, "Input Required"
        Cancel = True
    Else
        DOBText = Format(DOBText, "yyyy-mm-dd")
        MsgBox ("Date of Birth has been automatically converted" & vbNewLine & "to YYYY-MM-DD as per interface requirements." & vbNewLine & _
        vbNewLine & "Please continue entering data as required"), vbInformation, "Please note:"
    End If
End Sub
Code to write DOB textbox to spreadsheet
LastRow.Offset(1, 4).Value = Format(DOBText, "yyyy-mm-dd")
thanks for any help.