Excel confuses dd/mm when dd < 10

terrafutan

New Member
Joined
Nov 1, 2005
Messages
4
Hi all. I need some help with dates and Excel.

My short date regional format is dd/mm/yyyy.
I have a form with a textbox that initialises to yesterday and can be modified. 'TextBox64.Value = Format(Date - 1, "dd/mm/yyyy")'

When saving the form data to a sheet the following happens:
1. Where dd>12 it is captured correctly
2. Where dd<12 saves the dd as the month... it's driving me crazy.

For example today it populates 16/08/2023, I modify it four days ago, the 12/08/2023 and it's suddenly we're in December as the sheet is populated as 08/12/2023.

What am I missing?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If you are using code to assign the textbox value to a cell, use CDate to coerce it to a date value using your regional settings.
 
Upvote 1
What am I missing?
Once you bring it into the text box it is just a text string of 12/08/2023 and all VBA is in American date format of MM/DD/YYYY by default.
The 16/08/2023 works when you put it in a cell (but will be text not a real date) because it can't be coerced to an American format date, but the 12/08/2023 will be coerced to a date in the format mm/dd/yyyy (then the underlying value will go into the cell and take on whatever format the cell has and so becomes 08/12/2023 [12th December 2023]).

As @RoryA has stated use something like
VBA Code:
Range("A2").Value = CDate(TextBox64.text)
 
Last edited:
Upvote 1
Solution
Thanks guys, that sorted the issue out.

'all VBA is in American date format of MM/DD/YYYY by default.' this I wasn't aware of, interesting.

Upticked Mark as solver due to extra info, thanks :)
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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