Wrong format in date

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I am using this line of code in my macro but it gives the wrong date format
VBA Code:
    Range("Reports!H3").Value = Format(Now, "dd/mm/yyyy HH:mm:ss")
I am getting the date as mm/dd/yyyy and then hours and seconds
all other dates in the workbook are fine but it gets confusing when most dates are 10/9/2021 and this date is 9/10/2021 because the month is first.

I cannot seem to change this format, even in the cell and it is only when I run code for a date without the time that I get the right format.
I have checked all my regional settings and they are right.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
try this

Range("Reports!H3").Value = CDate(Now)
 
Upvote 0
Solution
Hi

Glad that helped, as for why, all i know is i have had so many date format issues with my projects over the years, that when i discovered this, probably by someone on here pointing me there, i always use this now.

i think it literally converts values into date.

i would say, dates in excel have been one of the most frustrating things i have ever had to deal with, especially automtic date recognittion.

maybe someone else has a better explination

but at least its working now

dave
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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