Date format when copying from csv file using VBA

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
I have a number of system-generated csv files which among other data, contains a list of dates. Manually copying and pasting the content of these works as expected, but using the below code results in the dates as US date format.

I've tried reformatting them within the code, or using text-to-columns but nothing seems to work. What am I doing wrong???

Code:
Sub Update()
Dim i As Integer
Dim sh As String
Dim Path As String
Dim This_File As String
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
Path = ThisWorkbook.Path
This_File = ThisWorkbook.Name
For i = 1 To 4
    sh = WorksheetFunction.Choose(i, "Onshore", "Offshore", "PL", "PL Offshore")
 
    Workbooks.Open Path & "\" & sh & ".csv"
    With Workbooks(sh & ".csv")
        .Sheets(sh).Cells.Copy Workbooks(This_File).Sheets(sh).Cells(1, 1)
        .Close False
    End With
 
Next i
Application .ScreenUpdating = True
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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