Date format switching to mm/dd/yyyy

Mr_Doug

New Member
Joined
Mar 29, 2016
Messages
8
Please help. Going insane.

I have a simple sheet with four columns (Date, Details, Reference & Value). I have a textbox on a user form to record a date, but when I submit that value to a cell it is converting it to US format.

I have a BeforeUpdate event on the textbox that coverts that value entered to date. This seems to work fine.

Private Sub tbDateInfo_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
' Me.tbDateInfo = CDate(Me.tbDateInfo)
Me.tbDateInfo = DateValue(Me.tbDateInfo)
End Sub


However, when running to code below, that date is swapped from UK to US format. My regional settings are correct, and the cell format is dd/mm/yyyy.

Private Sub SubmitEntry_Click()

Dim NextEmptyRow As Long
Sheets("Cash").Activate

NextEmptyRow = Application.WorksheetFunction. _
CountA(Range("A:A")) + 1

Cells(NextEmptyRow, 1) = tbDateInfo.Value
Cells(NextEmptyRow, 1).Select
Selection.NumberFormat = "dd/MM/yyyy;@"

Cells(NextEmptyRow, 2) = DetailsInfo.Value
Cells(NextEmptyRow, 3) = RefInfoCombi.Value
Cells(NextEmptyRow, 4) = ValueInfo.Value

End Sub

I would imagine this has been asked before but I was unable to find a solution.

Thanks in advance.

Doug
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You should be using CDate when assigning the value to the cell:

Code:
Cells(NextEmptyRow, 1) = CDate(tbDateInfo.Value)
 
Upvote 0
Thanks Rory.... That has worked.

Is there anyway to format the CDate on the BeforeUpdate event? This always converts to US format.
 
Upvote 0
Why do you need to format it there?
 
Upvote 0
Aesthetics I guess. If I enter 10/2 (10th Feb) when I tab away it converts to 2/10 (2nd Oct). When I submit the form it works (with your code suggestion) so the end result is OK it just might be confusing for some of the end users.

Thanks for your help, really appreciated.
 
Upvote 0
If you remove the BeforeUpdate code, it will just leave the entry as it is, so what I'm asking is why you need to format it there at all? CDate will use whatever your regional settings are to convert the text input to a true date value.
 
Upvote 0
Hi Rory, thanks for getting back to me again. That's what I've done so all working OK now.

Thanks for the original code change suggestion.

Doug
 
Upvote 0

Forum statistics

Threads
1,214,824
Messages
6,121,784
Members
449,049
Latest member
greyangel23

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