# VBA Userform Textbox Date Format



## pure vito (Dec 20, 2022)

Hi All,

I have an issue I have not been able to resolve with the properties of the textboxes alone, within my userform some of the textboxes are populated with dates from a sheet, the format of these dates in the sheet is DD/MM/YYYY
but when the textboxes in the userform are populated with these dates they show as MM/DD/YYYY, can anyone help correct this format please,

Thanks in advance,

Below is the full code and below this the code populating the date textboxes



```
Private Sub resetadd_Click()
    Dim errMsg      As String
    On Error GoTo errHandler
    'Stage 1
    errMsg = "This Name Is Not In The Database. Please Try Again. :D"
    Application.ScreenUpdating = False
    'Sheets("Home").Select
    Sheets("People").Visible = True
    Sheets("People").Select
    Sheets("People").Range("B4") = TextBox1.Value
    Range("C1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Range("C999").Select
    'ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    startdate.Value = Sheets("People").Range("E1000").Value
    service.Value = Sheets("People").Range("G1000").Value
    undays.Value = Sheets("People").Range("H1000").Value
    lieu.Value = Sheets("People").Range("K1000").Value
    earned.Value = Sheets("People").Range("J1000").Value
    floating.Value = Sheets("People").Range("I1000").Value
    area.Value = Sheets("People").Range("L1000").Value
    pass.Value = Sheets("People").Range("M1000").Value
    ID.Value = Sheets("People").Range("C1000").Value
    orical.Value = Sheets("People").Range("D1000").Value
    myhr.Value = Sheets("People").Range("F1000").Value
    contact.Value = Sheets("People").Range("N1000").Value
    email.Value = Sheets("People").Range("O1000").Value
    p60.Value = Sheets("People").Range("Q1000").Value
    p60c.Value = Sheets("People").Range("S1000").Value
    p60z.Value = Sheets("People").Range("U1000").Value
    longforks.Value = Sheets("People").Range("W1000").Value
    counter.Value = Sheets("People").Range("Y1000").Value
    reach.Value = Sheets("People").Range("AA1000").Value
    flatbed.Value = Sheets("People").Range("AC1000").Value
    bframe.Value = Sheets("People").Range("AE1000").Value
    cframe.Value = Sheets("People").Range("AG1000").Value
    eframe.Value = Sheets("People").Range("AI1000").Value
    phev.Value = Sheets("People").Range("AK1000").Value
    manual.Value = Sheets("People").Range("AM1000").Value
    If Worksheets("People").Range("P1000").Text = "yes" Then
        p60v.Value = True
    Else
        p60v.Value = False
    End If
    If Worksheets("People").Range("R1000").Text = "yes" Then
        p60cv.Value = True
    Else
        p60cv.Value = False
    End If
    If Worksheets("People").Range("T1000").Text = "yes" Then
        p60zv.Value = True
    Else
        p60zv.Value = False
    End If
    If Worksheets("People").Range("V1000").Text = "yes" Then
        longforksv.Value = True
    Else
        longforksv.Value = False
    End If
    If Worksheets("People").Range("X1000").Text = "yes" Then
        counterv.Value = True
    Else
        counterv.Value = False
    End If
    If Worksheets("People").Range("Z1000").Text = "yes" Then
        reachv.Value = True
    Else
        reachv.Value = False
    End If
    If Worksheets("People").Range("AB1000").Text = "yes" Then
        flatbedv.Value = True
    Else
        flatbedv.Value = False
    End If
    If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
    End If
    If Worksheets("People").Range("AF1000").Text = "yes" Then
        cframev.Value = True
    Else
        cframev.Value = False
    End If
    If Worksheets("People").Range("AH1000").Text = "yes" Then
        eframev.Value = True
    Else
        eframev.Value = False
    End If
    If Worksheets("People").Range("AJ1000").Text = "yes" Then
        phevv.Value = True
    Else
        phevv.Value = False
    End If
    If Worksheets("People").Range("AL1000").Text = "yes" Then
        manualv.Value = True
    Else
        manualv.Value = False
    End If
    Range("C800:AZ1200").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C800").Select
    ActiveSheet.Range("$C$1:$AM$989").AutoFilter Field:=1
    Range("C22").Select
    Selection.End(xlUp).Select
    Sheets("People").Select
    ActiveWindow.SelectedSheets.Visible = False
    'Sheets(LastSheet).Select
    Sheets("Home").Select
    Application.ScreenUpdating = True
    GoTo endProc
errHandler:
    MsgBox errMsg
endProc:
    TextBox1.Value = ""
    TextBox1.SetFocus
    Exit Sub
End Sub
```


Here are the textboxes populated with dates


```
If Worksheets("People").Range("P1000").Text = "yes" Then
        p60v.Value = True
    Else
        p60v.Value = False
    End If
    If Worksheets("People").Range("R1000").Text = "yes" Then
        p60cv.Value = True
    Else
        p60cv.Value = False
    End If
    If Worksheets("People").Range("T1000").Text = "yes" Then
        p60zv.Value = True
    Else
        p60zv.Value = False
    End If
    If Worksheets("People").Range("V1000").Text = "yes" Then
        longforksv.Value = True
    Else
        longforksv.Value = False
    End If
    If Worksheets("People").Range("X1000").Text = "yes" Then
        counterv.Value = True
    Else
        counterv.Value = False
    End If
    If Worksheets("People").Range("Z1000").Text = "yes" Then
        reachv.Value = True
    Else
        reachv.Value = False
    End If
    If Worksheets("People").Range("AB1000").Text = "yes" Then
        flatbedv.Value = True
    Else
        flatbedv.Value = False
    End If
    If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
    End If
    If Worksheets("People").Range("AF1000").Text = "yes" Then
        cframev.Value = True
    Else
        cframev.Value = False
    End If
    If Worksheets("People").Range("AH1000").Text = "yes" Then
        eframev.Value = True
    Else
        eframev.Value = False
    End If
    If Worksheets("People").Range("AJ1000").Text = "yes" Then
        phevv.Value = True
    Else
        phevv.Value = False
    End If
    If Worksheets("People").Range("AL1000").Text = "yes" Then
        manualv.Value = True
    Else
        manualv.Value = False
    End If
```


----------



## Gokhan Aycan (Dec 20, 2022)

Did you check Format function?

Format function (Visual Basic for Applications)


----------



## pure vito (Dec 20, 2022)

Gokhan Aycan said:


> Did you check Format function?
> 
> Format function (Visual Basic for Applications)


Hey, quickly scanning over that I'm not sure how this will help me as I don't understand it  😅  am I right in thinking the code needs to be changed? and if so I wouldn't know how to amend the code based on what I'm reading here


----------



## Georgiboy (Dec 20, 2022)

May also need to use CDate function as below:

```
startdate.Value = CDate(Sheets("People").Range("E1000").Value)
```


----------



## pure vito (Dec 20, 2022)

Georgiboy said:


> May also need to use CDate function as below:
> 
> ```
> startdate.Value = CDate(Sheets("People").Range("E1000").Value)
> ```


Hi Geogiboy, this would be the code that needs to be changed. I'm very much a novice =CDate by adding this in the code would it also need to be added at the top of the code? as String or something like that I have no clue  😬 


```
If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
```


----------



## Georgiboy (Dec 20, 2022)

It would be used where the date is passed to the textbox, I assumed that is the snippet I used?

Where the textbox is being populated from the worksheet.


----------



## pure vito (Dec 20, 2022)

Georgiboy said:


> It would be used where the date is passed to the textbox, I assumed that is the snippet I used?
> 
> Where the textbox is being populated from the worksheet.


Thanks for taking the time, This code has the corresponding textbox names this is populating the dates,


```
If Worksheets("People").Range("P1000").Text = "yes" Then
        p60v.Value = True
    Else
        p60v.Value = False
    End If
    If Worksheets("People").Range("R1000").Text = "yes" Then
        p60cv.Value = True
    Else
        p60cv.Value = False
    End If
    If Worksheets("People").Range("T1000").Text = "yes" Then
        p60zv.Value = True
    Else
        p60zv.Value = False
    End If
    If Worksheets("People").Range("V1000").Text = "yes" Then
        longforksv.Value = True
    Else
        longforksv.Value = False
    End If
    If Worksheets("People").Range("X1000").Text = "yes" Then
        counterv.Value = True
    Else
        counterv.Value = False
    End If
    If Worksheets("People").Range("Z1000").Text = "yes" Then
        reachv.Value = True
    Else
        reachv.Value = False
    End If
    If Worksheets("People").Range("AB1000").Text = "yes" Then
        flatbedv.Value = True
    Else
        flatbedv.Value = False
    End If
    If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
    End If
    If Worksheets("People").Range("AF1000").Text = "yes" Then
        cframev.Value = True
    Else
        cframev.Value = False
    End If
    If Worksheets("People").Range("AH1000").Text = "yes" Then
        eframev.Value = True
    Else
        eframev.Value = False
    End If
    If Worksheets("People").Range("AJ1000").Text = "yes" Then
        phevv.Value = True
    Else
        phevv.Value = False
    End If
    If Worksheets("People").Range("AL1000").Text = "yes" Then
        manualv.Value = True
    Else
        manualv.Value = False
    End If
```


----------



## Georgiboy (Dec 20, 2022)

That piece of the code is just setting true/ false, the values are being populated to the textboxes from dates on the sheet:


```
startdate.Value = Sheets("People").Range("E1000").Value
    service.Value = Sheets("People").Range("G1000").Value
    undays.Value = Sheets("People").Range("H1000").Value
    lieu.Value = Sheets("People").Range("K1000").Value
```


----------



## pure vito (Dec 20, 2022)

How silly of me  😅  hence why I'm here for help 😁 I made these changes however something is'nt working right now it's not giving me an error the VBA just isn't working as normal?


```
startdate.Value = Sheets("People").Range("E1000").Value
    service.Value = Sheets("People").Range("G1000").Value
    undays.Value = Sheets("People").Range("H1000").Value
    lieu.Value = Sheets("People").Range("K1000").Value
    earned.Value = Sheets("People").Range("J1000").Value
    floating.Value = Sheets("People").Range("I1000").Value
    area.Value = Sheets("People").Range("L1000").Value
    pass.Value = Sheets("People").Range("M1000").Value
    ID.Value = Sheets("People").Range("C1000").Value
    orical.Value = Sheets("People").Range("D1000").Value
    myhr.Value = Sheets("People").Range("F1000").Value
    contact.Value = Sheets("People").Range("N1000").Value
    email.Value = Sheets("People").Range("O1000").Value
    p60.Value = CDate(Sheets("People").Range("Q1000").Value)
    p60c.Value = CDate(Sheets("People").Range("S1000").Value)
    p60z.Value = CDate(Sheets("People").Range("U1000").Value)
    longforks.Value = CDate(Sheets("People").Range("W1000").Value)
    counter.Value = CDate(Sheets("People").Range("Y1000").Value)
    reach.Value = CDate(Sheets("People").Range("AA1000").Value)
    flatbed.Value = CDate(Sheets("People").Range("AC1000").Value)
    bframe.Value = CDate(Sheets("People").Range("AE1000").Value)
    cframe.Value = CDate(Sheets("People").Range("AG1000").Value)
    eframe.Value = CDate(Sheets("People").Range("AI1000").Value)
    phev.Value = CDate(Sheets("People").Range("AK1000").Value)
    manual.Value = CDate(Sheets("People").Range("AM1000").Value)
```


----------



## Georgiboy (Dec 20, 2022)

What are you seeing in the textboxes now?

You need to give a little more detail on "the VBA just isn't working as normal?"


----------



## pure vito (Dec 20, 2022)

Hi All,

I have an issue I have not been able to resolve with the properties of the textboxes alone, within my userform some of the textboxes are populated with dates from a sheet, the format of these dates in the sheet is DD/MM/YYYY
but when the textboxes in the userform are populated with these dates they show as MM/DD/YYYY, can anyone help correct this format please,

Thanks in advance,

Below is the full code and below this the code populating the date textboxes



```
Private Sub resetadd_Click()
    Dim errMsg      As String
    On Error GoTo errHandler
    'Stage 1
    errMsg = "This Name Is Not In The Database. Please Try Again. :D"
    Application.ScreenUpdating = False
    'Sheets("Home").Select
    Sheets("People").Visible = True
    Sheets("People").Select
    Sheets("People").Range("B4") = TextBox1.Value
    Range("C1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Range("C999").Select
    'ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    startdate.Value = Sheets("People").Range("E1000").Value
    service.Value = Sheets("People").Range("G1000").Value
    undays.Value = Sheets("People").Range("H1000").Value
    lieu.Value = Sheets("People").Range("K1000").Value
    earned.Value = Sheets("People").Range("J1000").Value
    floating.Value = Sheets("People").Range("I1000").Value
    area.Value = Sheets("People").Range("L1000").Value
    pass.Value = Sheets("People").Range("M1000").Value
    ID.Value = Sheets("People").Range("C1000").Value
    orical.Value = Sheets("People").Range("D1000").Value
    myhr.Value = Sheets("People").Range("F1000").Value
    contact.Value = Sheets("People").Range("N1000").Value
    email.Value = Sheets("People").Range("O1000").Value
    p60.Value = Sheets("People").Range("Q1000").Value
    p60c.Value = Sheets("People").Range("S1000").Value
    p60z.Value = Sheets("People").Range("U1000").Value
    longforks.Value = Sheets("People").Range("W1000").Value
    counter.Value = Sheets("People").Range("Y1000").Value
    reach.Value = Sheets("People").Range("AA1000").Value
    flatbed.Value = Sheets("People").Range("AC1000").Value
    bframe.Value = Sheets("People").Range("AE1000").Value
    cframe.Value = Sheets("People").Range("AG1000").Value
    eframe.Value = Sheets("People").Range("AI1000").Value
    phev.Value = Sheets("People").Range("AK1000").Value
    manual.Value = Sheets("People").Range("AM1000").Value
    If Worksheets("People").Range("P1000").Text = "yes" Then
        p60v.Value = True
    Else
        p60v.Value = False
    End If
    If Worksheets("People").Range("R1000").Text = "yes" Then
        p60cv.Value = True
    Else
        p60cv.Value = False
    End If
    If Worksheets("People").Range("T1000").Text = "yes" Then
        p60zv.Value = True
    Else
        p60zv.Value = False
    End If
    If Worksheets("People").Range("V1000").Text = "yes" Then
        longforksv.Value = True
    Else
        longforksv.Value = False
    End If
    If Worksheets("People").Range("X1000").Text = "yes" Then
        counterv.Value = True
    Else
        counterv.Value = False
    End If
    If Worksheets("People").Range("Z1000").Text = "yes" Then
        reachv.Value = True
    Else
        reachv.Value = False
    End If
    If Worksheets("People").Range("AB1000").Text = "yes" Then
        flatbedv.Value = True
    Else
        flatbedv.Value = False
    End If
    If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
    End If
    If Worksheets("People").Range("AF1000").Text = "yes" Then
        cframev.Value = True
    Else
        cframev.Value = False
    End If
    If Worksheets("People").Range("AH1000").Text = "yes" Then
        eframev.Value = True
    Else
        eframev.Value = False
    End If
    If Worksheets("People").Range("AJ1000").Text = "yes" Then
        phevv.Value = True
    Else
        phevv.Value = False
    End If
    If Worksheets("People").Range("AL1000").Text = "yes" Then
        manualv.Value = True
    Else
        manualv.Value = False
    End If
    Range("C800:AZ1200").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C800").Select
    ActiveSheet.Range("$C$1:$AM$989").AutoFilter Field:=1
    Range("C22").Select
    Selection.End(xlUp).Select
    Sheets("People").Select
    ActiveWindow.SelectedSheets.Visible = False
    'Sheets(LastSheet).Select
    Sheets("Home").Select
    Application.ScreenUpdating = True
    GoTo endProc
errHandler:
    MsgBox errMsg
endProc:
    TextBox1.Value = ""
    TextBox1.SetFocus
    Exit Sub
End Sub
```


Here are the textboxes populated with dates


```
If Worksheets("People").Range("P1000").Text = "yes" Then
        p60v.Value = True
    Else
        p60v.Value = False
    End If
    If Worksheets("People").Range("R1000").Text = "yes" Then
        p60cv.Value = True
    Else
        p60cv.Value = False
    End If
    If Worksheets("People").Range("T1000").Text = "yes" Then
        p60zv.Value = True
    Else
        p60zv.Value = False
    End If
    If Worksheets("People").Range("V1000").Text = "yes" Then
        longforksv.Value = True
    Else
        longforksv.Value = False
    End If
    If Worksheets("People").Range("X1000").Text = "yes" Then
        counterv.Value = True
    Else
        counterv.Value = False
    End If
    If Worksheets("People").Range("Z1000").Text = "yes" Then
        reachv.Value = True
    Else
        reachv.Value = False
    End If
    If Worksheets("People").Range("AB1000").Text = "yes" Then
        flatbedv.Value = True
    Else
        flatbedv.Value = False
    End If
    If Worksheets("People").Range("AD1000").Text = "yes" Then
        bframev.Value = True
    Else
        bframev.Value = False
    End If
    If Worksheets("People").Range("AF1000").Text = "yes" Then
        cframev.Value = True
    Else
        cframev.Value = False
    End If
    If Worksheets("People").Range("AH1000").Text = "yes" Then
        eframev.Value = True
    Else
        eframev.Value = False
    End If
    If Worksheets("People").Range("AJ1000").Text = "yes" Then
        phevv.Value = True
    Else
        phevv.Value = False
    End If
    If Worksheets("People").Range("AL1000").Text = "yes" Then
        manualv.Value = True
    Else
        manualv.Value = False
    End If
```


----------



## pure vito (Dec 20, 2022)

The first textbox is populating and the rest are not, also the message box telling me the data can not be found is popping up and stopping the VBA from completing,

After testing this seems to work but the one below doesn't, does it only need to be added once?


```
p60.Value = CDate(Sheets("People").Range("Q1000").Value)
    p60c.Value = Sheets("People").Range("S1000").Value
    p60z.Value = Sheets("People").Range("U1000").Value
    longforks.Value = Sheets("People").Range("W1000").Value
    counter.Value = Sheets("People").Range("Y1000").Value
    reach.Value = Sheets("People").Range("AA1000").Value
    flatbed.Value = Sheets("People").Range("AC1000").Value
    bframe.Value = Sheets("People").Range("AE1000").Value
    cframe.Value = Sheets("People").Range("AG1000").Value
    eframe.Value = Sheets("People").Range("AI1000").Value
    phev.Value = Sheets("People").Range("AK1000").Value
    manual.Value = Sheets("People").Range("AM1000").Value
```

This does not work


```
p60.Value = CDate(Sheets("People").Range("Q1000").Value)
    p60c.Value = CDate(Sheets("People").Range("S1000").Value)
    p60z.Value = CDate(Sheets("People").Range("U1000").Value)
    longforks.Value = CDate(Sheets("People").Range("W1000").Value)
    counter.Value = CDate(Sheets("People").Range("Y1000").Value)
    reach.Value = CDate(Sheets("People").Range("AA1000").Value)
    flatbed.Value = CDate(Sheets("People").Range("AC1000").Value)
    bframe.Value = CDate(Sheets("People").Range("AE1000").Value)
    cframe.Value = CDate(Sheets("People").Range("AG1000").Value)
    eframe.Value = CDate(Sheets("People").Range("AI1000").Value)
    phev.Value = CDate(Sheets("People").Range("AK1000").Value)
    manual.Value = CDate(Sheets("People").Range("AM1000").Value)
```


----------



## Georgiboy (Dec 20, 2022)

Does the range: 'Sheets("People").Range("S1000").Value' contain a date or just the word 'yes'?
If it is a date does excel recognise it as a date or is it text?

Could there be any other code that could be poulating the textboxes with dates?


----------



## pure vito (Dec 20, 2022)

In the sheet, the column with the date is formatted to short date, but I think you have solved it Georgiboy by adding CDate to the one of those lines it seems to have formatted them all to DD/MM/YYYY so I'm going to call this solved! thank you


----------

