Hi all,
I found this nice code that merges all files in a folder into one master file.
Sub MergeFilesMultiSheetsPath1()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim MyPath As String
Dim strFilename As String
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
MyPath = Range("pathW").Value ' change to suit
Set wbDst = Workbooks.Add(xlWBATWorksheet)
strFilename = Dir(MyPath & "\*.csv", vbNormal) '"\*.xls"
If Len(strFilename) = 0 Then Exit Sub
Do Until strFilename = ""
Set wbSrc = Workbooks.Open(FileName:=MyPath & "\" & strFilename)
Set wsSrc = wbSrc.Worksheets(1)
wsSrc.Copy After:=wbDst.Worksheets(wbDst.Worksheets.Count)
wbSrc.Close False
strFilename = Dir()
Loop
wbDst.Worksheets(1).Delete
For i = 1 To Sheets.Count
ActiveWorkbook.Sheets(i).Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False
Next i
IgualNumeroFilas
ActiveWorkbook.Close saveChanges:=True, FileName:=MyPath & "/Master.xlsx"
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
It has been working fine during some time until I faced the workbook attched. If I double-click on the file then you may see that the file it's ok and all columns and rows are not equal to zero. However, when running the macro something is going wrong and the master file that is created has a lot of blanks (missing information) on it. Does anybody know what's wrong and how can I solve it?
I've been trying hard to make it work but finally I always get the same result, only the first 25 columns are filled up instead of 380.
Bookmarks