LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 2
Default VBA code To Merge All .csv files into a single excel sheet (data start from row 11th)

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Multiple Single Worksheet Excel Files into one file in separ dbguy11 Excel Discussion (Misc queries) 6 April 3rd 23 04:20 PM
start Word and Mail Merge the data from excel,system will restart tmssupport Excel Discussion (Misc queries) 2 December 18th 07 03:15 PM
Batch file to start multiple excel files with auto_open() macro. Delay code needed [email protected] Excel Programming 9 May 29th 05 07:02 AM
Way to change a single line of vb code in several hundred excel files? bball887 Excel Programming 2 December 16th 03 03:24 PM
Way to change a single line of vb code in several hundred excel files? Alex[_13_] Excel Programming 0 December 15th 03 06:13 PM


All times are GMT +1. The time now is 01:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"