Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
Hi All VBA experts:
I have 1000+ data files stored in csv. All of these files have the same structure& format. I use a vba code written by abousetta To merge it into one spreadsheet automatically, but the problem is,the data i needed start only from row 11 onward. Is there a way to modify the code to allow this to happen? Here's my requirement on the code: 1) Must be able to merge all the file csv file in on shoot, 2) Data needed start from 11th row onward, 3) after open each file, copy the data from 11th row and onward, copy and paste it into MasterCSV sheet, the next data will be paste to the same column but next row to the previous data copied... I attach one of my file into the thread... [quote] Option Explicit Sub CombineCSVFiles() Dim sCSV$, sCombCSV$, iFF% Dim myFolder, myFile, arrCSV Dim myRange As Range Dim fso As Object Dim fPath As String ' Turn off some Excel functionality so your code runs faster With Application .ScreenUpdating = False .DisplayStatusBar = False .EnableEvents = False .Calculation = xlCalculationManual End With ' Use File System Object to choose folder with files Set fso = CreateObject("Scripting.FileSystemObject") With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show .InitialFileName = ThisWorkbook.Path & "\" ' Default path - Change as required .Title = "Please Select a Folder" .ButtonName = "Select Folder" If .SelectedItems.Count 0 Then fPath = .SelectedItems(1) & "\" Else Exit Sub End With ' Open each file consequently and merge into a variable iFF = FreeFile Set myFolder = fso.GetFolder(fPath).Files For Each myFile In myFolder If LCase(myFile) Like "*.csv" Then sCSV = Space(FileLen(myFile)) Open myFile For Binary Access Read As #iFF Get #iFF, , sCSV sCombCSV = sCombCSV & sCSV Close #iFF End If ' Loop through all files in folder Next myFile ' Convert variable to array arrCSV = Split(sCombCSV, vbCrLf) ' Paste data back to Excel Set myRange = Range(Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1), Range("A" & Rows.Count).End(xlUp).Offset(UBound(arrCSV) + 1)) myRange = Application.Transpose(arrCSV) myRange.TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=False, Comma:=True ' clean up myFile = vbNullString iFF = 1 ' Turn Excel functionality back on With Application .DisplayStatusBar = True .EnableEvents = True .Calculation = xlCalculationAutomatic End With End Sub [quote] |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Merge Multiple Single Worksheet Excel Files into one file in separ | Excel Discussion (Misc queries) | |||
start Word and Mail Merge the data from excel,system will restart | Excel Discussion (Misc queries) | |||
Batch file to start multiple excel files with auto_open() macro. Delay code needed | Excel Programming | |||
Way to change a single line of vb code in several hundred excel files? | Excel Programming | |||
Way to change a single line of vb code in several hundred excel files? | Excel Programming |