Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combine csv files


Hello...Everyday a folder is created with a certain amount of csv files.
Each one is the same format, line one is the field names and line two
has all the info. Is there a way of combining all the files into one
file, leaving off the field names, without importing each one manually.
The amount of files and the file names are never the same and the
amount of files can range anywhere from 10 to 100.

Thanks in advance for any help you can offer.

Jeff


--
RevJeff
------------------------------------------------------------------------
RevJeff's Profile: http://www.excelforum.com/member.php...o&userid=32201
View this thread: http://www.excelforum.com/showthread...hreadid=519493

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Combine csv files

Hi RevJeff

This is fast but not for you because you only want row 2
http://www.rondebruin.nl/csv.htm

You can open the files and copy row 2 with code like this
http://www.rondebruin.nl/copy3.htm

Change the folder in the code

Sub Example2()
Dim MyPath As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long

'Fill in the path\folder where the files are
'MyPath = "C:\Data" or on a network :
MyPath = "\\ComputerName\YourFolder"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.csv")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

On Error GoTo CleanUp
Application.ScreenUpdating = False
Set basebook = ThisWorkbook
'clear all cells on the first sheet
basebook.Worksheets(1).Cells.Clear
rnum = 1

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath < ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
Set sourceRange = mybook.Worksheets(1).Range("A2:IV2")
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Range("A" & rnum)

sourceRange.Copy destrange

rnum = rnum + SourceRcount
mybook.Close savechanges:=False
Next Fnum
End If
CleanUp:
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"RevJeff" wrote in message
...

Hello...Everyday a folder is created with a certain amount of csv files.
Each one is the same format, line one is the field names and line two
has all the info. Is there a way of combining all the files into one
file, leaving off the field names, without importing each one manually.
The amount of files and the file names are never the same and the
amount of files can range anywhere from 10 to 100.

Thanks in advance for any help you can offer.

Jeff


--
RevJeff
------------------------------------------------------------------------
RevJeff's Profile: http://www.excelforum.com/member.php...o&userid=32201
View this thread: http://www.excelforum.com/showthread...hreadid=519493



Reply
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
How can I combine several excel files into one? Crystal Lee Excel Worksheet Functions 3 February 5th 09 10:14 AM
combine 2 files into one Calculate Date range Excel Worksheet Functions 3 November 14th 06 02:37 PM
Combine many exel files to one MichalH Excel Worksheet Functions 1 March 27th 06 05:52 PM
combine two files Charles Excel Discussion (Misc queries) 1 August 9th 05 09:46 PM
Combine files andibevan Excel Programming 1 November 11th 04 04:12 PM


All times are GMT +1. The time now is 08:36 PM.

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

About Us

"It's about Microsoft Excel"