Date format problem when using macro

jt42cwr

Board Regular
Joined
Apr 11, 2007
Messages
50
Hi,

I am having a little trouble using a macro when copying some dates in that it mixes up UK and US date formats.

I have a .csv file in which in one column there are some date values in the UK format "dd/mm/yyyy", such as 10/08/2010 for 10th August 2010. Now, when I open this .csv file, and manually copy & paste values this column to my Excel workbook with the column already formatted to the UK date format it works fine. If however I do this using a macro it converts the cells format in the Excel workbook to *14/03/2001 and the date will now read 08/10/2010 instead of 10/08/2010.

Can anyone help with this?

Code:
'Copy dates
Windows("LPS load orders data.csv").Activate
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Copy
Windows("OMS booking time generator.xls").Activate
Sheets("Links").Select
Columns("C:C").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
 

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.
Annoying, isn't it?
I had the same problem with a .csv file and overcame the problem by opening the file in the following way:
Code:
Set wbInput = Workbooks.Open(oFileItem, Local:=True)
I believe that the 'Local' argument causes the PC date format to be used.
In this example, oFileItem is an object assigned to the .csv file but could have been something like "C:\LPS load orders data.csv"
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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