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
Bookmarks