Excel Date Time Format Changes Automatically

Shumai

New Member
Joined
Jun 27, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi can anyone help me with my problem,

I'm trying to insert a value from another wb to another wb using macro. The source date is 1/7/2021 but when the macro insert the value in another wb the date changes to 7/1/2021. How to prevent the cell value to change its date format?

The data type for the date in the source file is "Short Date"

Thanks and regards,
Shumai

Excel Error.PNG
Excel Code.PNG
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome!

I am assuming that "7/1/2021" is your locale default date format. You can use Range.NumberFormat to set the format of your dates. You could call it either as you enter the value for each date, or once you are finished on the entire range of dates, either should be ok. In the latter case, the code would look like
VBA Code:
SheetName.Range("A2:A18").NumberFormat = "m/d/yyyy"
, or whichever format you need.
 
Upvote 0
Solution
Welcome!

I am assuming that "7/1/2021" is your locale default date format. You can use Range.NumberFormat to set the format of your dates. You could call it either as you enter the value for each date, or once you are finished on the entire range of dates, either should be ok. In the latter case, the code would look like
VBA Code:
SheetName.Range("A2:A18").NumberFormat = "m/d/yyyy"
, or whichever format you need.
Thank you sir! I have solved the problem. The system date time format was set to US format. Changed to UK everything paste accordingly.
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,665
Members
449,114
Latest member
aides

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