Adding Date to cell via Userform, Date swaps Day with Month...

Chrisjd2

Board Regular
Joined
Mar 1, 2016
Messages
61
Hi All,

Hope you can help.

As per the description, when I enter a date into my userform which then puts it into a cell, sometimes excel swaps the Day with the Month, which I dont want. This is frustrating, sometimes it does it, sometimes it doesn't, depending on the date. I have tried to force the cell but that doesn't work either. What I enter in the userform TB must be the date shown in the cell, I don't understand why it insists on changing it.

My PC settings on the clock is set to British Time / Britsh Date..

Here is some of my code I have used to enter the date into the cell and also to try and force the date correctly.

Code:
        If TrialDateTB.Text <> "" Then 
           DT = TrialDateTB.Text
            ws.Cells(crow, 7) = DT
            ws.Cells(crow, 7) = Format(DT, "dd/mm/yyyy")
            ws.Cells(crow, 7).HorizontalAlignment = xlRight
        End If
        
        If ClosingDateTB.Text <> "" Then
            DT = ClosingDateTB.Text
            ws.Cells(crow, 8) = DT
            ws.Cells(crow, 8) = Format(DT, "dd/mm/yyyy")
            ws.Cells(crow, 8).HorizontalAlignment = xlRight
        End If
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Don't use Format, use DateValue then format the cell as required.
Code:
    If TrialDateTB.Text <> "" Then
    DT = TrialDateTB.Text
    With ws.Cells(crow, 7)
        .Value = DateValue(DT)
        .NumberFormat = "dd/mm/yyyy"
        .HorizontalAlignment = xlRight
    End With

End If

If ClosingDateTB.Text <> "" Then
    DT = ClosingDateTB.Text
    With ws.Cells(crow, 8)
        .Value = DateValue(DT)
        .NumberFormat = "dd/mm/yyyy"
        .HorizontalAlignment = xlRight
    End With
End If
 
Upvote 0
Don't use Format, use DateValue then format the cell as required.
Code:
    If TrialDateTB.Text <> "" Then
    DT = TrialDateTB.Text
    With ws.Cells(crow, 7)
        .Value = DateValue(DT)
        .NumberFormat = "dd/mm/yyyy"
        .HorizontalAlignment = xlRight
    End With

End If

If ClosingDateTB.Text <> "" Then
    DT = ClosingDateTB.Text
    With ws.Cells(crow, 8)
        .Value = DateValue(DT)
        .NumberFormat = "dd/mm/yyyy"
        .HorizontalAlignment = xlRight
    End With
End If

THANKYOU!!!! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,318
Members
453,032
Latest member
Pauh

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