CSV Import US Date Format

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm sure this has been covered but I cannot find the answer. I have a csv import that has in column A a date and time, I have downloaded this csv for say just Feb, it works well but I cannot change the date format to UK.
This is causing an issue as when the date reaches after the 12th of the month it gets confused. I really need it to read as UK format so I can filter correctly. I've tried a number of things so far including text to columns but cannot seem to get it to work.

Can someone please help me with this?

Please!

US Date Format.jpg
 
Is it separating the data into more than one column or is all of the data in one column after run?

Should there be more than one column?
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Is it separating the data into more than one column or is all of the data in one column after run?

Should there be more than one column?
I have data in columns A-K but the date time issue is in column A,
 
Upvote 0
Does the below rectify the date?
VBA Code:
Sub test()
    Dim fPath As String
   
    fPath = "C:\Users\jbloggs\Desktop\test\sample.csv" '< path of csv file

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fPath, Destination:=Range("$A$1"))
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileCommaDelimiter = True
        .TextFileColumnDataTypes = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .Refresh BackgroundQuery:=False
    End With
End Sub
 
Upvote 0
Does the below rectify the date?
VBA Code:
Sub test()
    Dim fPath As String
  
    fPath = "C:\Users\jbloggs\Desktop\test\sample.csv" '< path of csv file

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fPath, Destination:=Range("$A$1"))
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileCommaDelimiter = True
        .TextFileColumnDataTypes = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .Refresh BackgroundQuery:=False
    End With
End Sub
Unfortunately no, I still get the same, see screenshot below

US Date Format2.jpg
 
Upvote 0
@rfletcher35 - things changed when I included Time into the test data. This might work for you.

VBA Code:
Sub Open_CSV_US()
    Dim strPath As String
    strPath = "C:\Users\jbloggs\Desktop\test\sample.csv"
    Workbooks.OpenText Filename:=strPath, DataType:=xlDelimited, _
      TextQualifier:=xlTextQualifierNone, Comma:=True, Local:=True

'    Convert Dates in Column A
    Dim rngDate As Range, cellDate As Range
    Dim sTemp As String
    Dim pt1 As Variant
    Dim pt2 As Variant

    Set rngDate = Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))    ' <-- If you have a header row change change this from row 1 to 2
    rngDate.Columns.AutoFit
    For Each cellDate In rngDate
        sTemp = cellDate.Text
        Debug.Print sTemp
        pt1 = Split(sTemp, " ")
        pt2 = Split(pt1(0), "/")
        sTemp = DateSerial(pt2(2), pt2(0), pt2(1)) + TimeValue(pt1(1))
        cellDate.Value = CDate(sTemp)
    Next cellDate

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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