VBA - my month and day format keep being switched around?

NessPJ

Active Member
Joined
May 10, 2011
Messages
420
Office Version
  1. 365
Hello,

In my VBA routine i have 2 lines of code that i user every now and then to put (log) the current date/time somewhere.

VBA Code:
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).NumberFormat = "DD-MM-YY hh:mm"
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).Value = Format(Now, "dd-mm-yy hh:mm")

When the Day of the month can be interpreted as a Month, Excel suddenly seems to turn these 2 around in the value that is being show (very annoying).
For example, when i run this today, the output will be: 11-06-20 09:20
As soon as the 13th day of the month is reached. This is no longer a problem and the same code will suddenly show: 13-11-20 09:20

What can i do to solve this? I hope its not a System Region thing...because i would like to solve it within the VBA.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Don't use Format and switch the order of the code.
VBA Code:
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).Value = Now
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).NumberFormat = "DD-MM-YY hh:mm"
 
Upvote 0
Don't use Format and switch the order of the code.
VBA Code:
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).Value = Now
Sheets("Masterdata").Range(Foundvalue).Offset(0, 4).NumberFormat = "DD-MM-YY hh:mm"
That solved it, thanks!
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

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