Techie
Techie

Reputation: 181

How to keep csv file dateformat in excel

dateformat of csv file is "yyyy-mm-dd" when open in excel it shows dd/mm/yyyy I want to show the original format in excel

thanks

Upvotes: 0

Views: 61

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

Starting with data like:

enter image description here

Try running a macro like:

Sub GetDatesFromCSV()

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\JamesRavenswood\Desktop\temp.csv", Destination:=Range("$A$1"))
        .Name = "temp"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(5)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

    Range("A:A").NumberFormat = "yyy-mm-dd"
End Sub

Upvotes: 1

Related Questions