Results 1 to 11 of 11

Date format changed after csv files imported to current excel workbook

Threaded View

  1. #1
    Registered User
    Join Date
    09-16-2018
    Location
    Melbourne
    MS-Off Ver
    1830
    Posts
    3

    Date format changed after csv files imported to current excel workbook

    Greetings all.

    I am a VBA newbie, currently studying and working on a personal project importing multiple .csv documents into my current workbook with their own different sheet, but I'm stuck at a stage where after csv files been imported to my current workbook, some dates are converted to mm/dd/yyyy, while their original formates are dd/mm/yyyy in csv. Also, some of the dates changed to 'general' type. As I am using dd/mm/yyyy format and aim to run date range filter, it always gave me incorrect outcome. I have now located the issue and have no idea how to fix them.

    After I run the followling macro, it imports my selected csv files and merge them with my current workbook, and the flexibility is my greatly prefered. It just the date format that confusing me. I have attached file1.csv which is one of my original file.

    Currnet VBA I am using as follows.
    Sub MergeFileandChangeName()
        Dim fnameList, fnameCurFile As Variant
        Dim countFiles, countSheets As Integer
        Dim wksCurSheet As Worksheet
        Dim wbkCurBook, wbkSrcBook As Workbook
     
        fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.csv),*.csv", Title:="Choose Excel files to merge", MultiSelect:=True)
     
        If (vbBoolean <> VarType(fnameList)) Then
     
            If (UBound(fnameList) > 0) Then
                countFiles = 0
                countSheets = 0
     
                Application.ScreenUpdating = False
                Application.Calculation = xlCalculationManual
     
                Set wbkCurBook = ActiveWorkbook
     
                For Each fnameCurFile In fnameList
     
                    Set wbkSrcBook = Workbooks.Open(Filename:=fnameCurFile)
                     
                    For Each wksCurSheet In wbkSrcBook.Sheets
                        wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
                    Next
     
                    wbkSrcBook.Close SaveChanges:=False
     
                Next
     
                Application.ScreenUpdating = True
                Application.Calculation = xlCalculationAutomatic
     
    
            End If
     
        Else
            MsgBox "No files selected", Title:="Merge Files"
        End If
    
    End Sub
    After I run the macro, the dates becomes totally different as what shown on csv file. see attachment 'Screen Capture' (list on the left side are incorrect data, left aligned are general type and right aligned are mm/dd/yyyy, and list on the right side are original data, which are what I wantted).

    Hope I have explained my confusion.

    Please kindly advise how can I fix the problem. Any help would be greatly appreciated. Thank you
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by FDibbins; 09-16-2018 at 11:31 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Multiple Text files imported in the current workbook.
    By dazziphoenix in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2014, 11:50 AM
  2. Replies: 6
    Last Post: 03-05-2010, 12:48 PM
  3. Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. [SOLVED] Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 AM
  5. [SOLVED] Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. [SOLVED] Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  7. [SOLVED] Imported Date & Time format with calcs. managed in excel from imrp
    By Todd F. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1