Bring different .csv files in to one single Excel work book

K

Karthik

I've been generating .csv files daily which contains data of 5 columns and
roughly 2000 rows. Could all these file be brought into one single Excel
work book with each day as a separate worksheet?

I tried downloading the ADD ins from http://www.rondebruin.nl/copy2.htm
but this add in merges all the files in one single work sheet.

Please let me know if anyone knows a way to automate it.

Thanks in Advance.....
 
D

Daniel.C

Try the following macro. You may select one or more files in the dialog
box.

Sub test()
Dim Rec As String, Tabl, myRow As Long
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "CSV Files", "*.CSV"
.Show
For i = 1 To .SelectedItems.Count
Sheets.Add
Close #1
Open .SelectedItems(i) For Input As #1
Do While Not EOF(1)
Line Input #1, Rec
Tabl = Split(Rec, ";")
myRow = myRow + 1
For j = 0 To UBound(Tabl)
Cells(myRow, j + 1) = Tabl(j)
Next j
Loop
Close #1
Next i
End With
End Sub

HTH
Daniel
 
D

Daniel.C

NB.
Replace :
Tabl = Split(Rec, ";")
with
Tabl = Split(Rec, ",")
to fit your regional settings.
Daniel
 
D

Dave Peterson

Maybe

tabl = split(rec, Application.International(xlListSeparator))

(I'm not sure if this is available in all versions, though.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top