Date formats being switched between UK / US formats when possible...

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,227
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Hey All

Weird one here, I've had this before but I've always been able to bodge my way around it somehow, but this time I can't and it's finally time to try and solve the problem once and for all.

I'm from the UK - When I'm using VBA to copy and paste a worksheet from a workbook on our company network drive to a workbook on my local desktop that has dates in it, the dates that can be changed to US format are being.

So, for example;

26/06/2018
26/06/2018
11/06/2018
11/06/2018
25/06/2018
25/06/2018


<colgroup><col></colgroup><tbody>
</tbody>
Becomes...

26/06/2018
26/06/2018
06/11/2018
06/11/2018
25/06/2018
25/06/2018

<colgroup><col></colgroup><tbody>
</tbody>

What was the 11th June 2018 becomes 6th November 2018, the other dates that can't be swapped around aren't.

It's not a formatting issue I don't think as the value is being changed from 43262 (11/06) to 43410 (06/11)

I've checked the "Locale" information in both Excel and Control Panel, both are set correctly to English (United Kingdom)

If I just open the Workbook on the network drive and copy and paste the sheet into a new workbook manually, the dates remain correct.

It's not just these dates that are being swapped around, any time the day / month can be swapped and made into a US format date it is being doing 11/12 becomes 12/11 and 06/07 becomes 07/06 etc.

There is nothing fancy about the code I'm using to copy and paste the worksheet;

Code:
    Workbooks.Open Filename:="Z:\Pricing Sheets\Pricing Analyser - " & FName & ".xlsm", ReadOnly:=True, UpdateLinks:=xlUpdateLinksAlways
    ActiveSheet.AutoFilterMode = False
    Cells.EntireColumn.Hidden = False
    Cells.Copy
    ActiveWorkbook.Close savechanges:=False
    ActiveSheet.Paste

(Fname is just the variable part of the filename defined by a Cell earlier in the code)

This makes no sense to me :(

Anyone come across anything like this before?
 
It avoids copy/paste completely and assigns the values from the source workbook directly to an array, then assigns that array directly to the values of the relevant range in the destination workbook.

Sorry, I got busy / distracted yesterday - Just wanted to say thanks for your help, the solution and the explanation - I'll be able to properly solve a few more problems with this most likely, I'll have a read up on it all a bit more now that I know about it.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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