Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Excel - merging numerous files

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Excel - merging numerous files

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Excel - merging numerous files

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Excel - merging numerous files

You should in VBA menu Insert - Module. And put code in new module. The
Folder need to be the complete folder name with a backslash at the end like I
did.

"drumbumuk" wrote:

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Excel - merging numerous files

Joel

Many thanks - learn something new every day. Now have discovered that the
server that sends these files has given each sheet a unique name, so i guess
i will be renamining them.

Thanks

"Joel" wrote:

You should in VBA menu Insert - Module. And put code in new module. The
Folder need to be the complete folder name with a backslash at the end like I
did.

"drumbumuk" wrote:

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Excel - merging numerous files

How many sheets are in the workbooks. Yo can always use a index number to
get the sheets. Instead of sheets("Sheet1") use Sheets(1). This will get
the first sheet no matter what the name is. If there was more than one
worksheet in each book you can modify the macro to get all the data.

"drumbumuk" wrote:

Joel

Many thanks - learn something new every day. Now have discovered that the
server that sends these files has given each sheet a unique name, so i guess
i will be renamining them.

Thanks

"Joel" wrote:

You should in VBA menu Insert - Module. And put code in new module. The
Folder need to be the complete folder name with a backslash at the end like I
did.

"drumbumuk" wrote:

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Excel - merging numerous files

Many Many Thanks

This has worked brilliantly. Save me a lot of time!

Ant

"Joel" wrote:

How many sheets are in the workbooks. Yo can always use a index number to
get the sheets. Instead of sheets("Sheet1") use Sheets(1). This will get
the first sheet no matter what the name is. If there was more than one
worksheet in each book you can modify the macro to get all the data.

"drumbumuk" wrote:

Joel

Many thanks - learn something new every day. Now have discovered that the
server that sends these files has given each sheet a unique name, so i guess
i will be renamining them.

Thanks

"Joel" wrote:

You should in VBA menu Insert - Module. And put code in new module. The
Folder need to be the complete folder name with a backslash at the end like I
did.

"drumbumuk" wrote:

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default Excel - merging numerous files

See also
http://www.rondebruin.nl/merge.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"drumbumuk" wrote in message ...
Many Many Thanks

This has worked brilliantly. Save me a lot of time!

Ant

"Joel" wrote:

How many sheets are in the workbooks. Yo can always use a index number to
get the sheets. Instead of sheets("Sheet1") use Sheets(1). This will get
the first sheet no matter what the name is. If there was more than one
worksheet in each book you can modify the macro to get all the data.

"drumbumuk" wrote:

Joel

Many thanks - learn something new every day. Now have discovered that the
server that sends these files has given each sheet a unique name, so i guess
i will be renamining them.

Thanks

"Joel" wrote:

You should in VBA menu Insert - Module. And put code in new module. The
Folder need to be the complete folder name with a backslash at the end like I
did.

"drumbumuk" wrote:

Many thanks for that, but i dont know how to use macros - i assumed to use MS
Visual Basic editor, copy the script below and change 'Folder' and 'Fname'?

Do i need to use the full folder/fname address?



"Joel" wrote:

the best way is to put all the files in one directory and then run the macro
below. Modify the Folder location and the Sheet Names ("Sheet1").


Sub MergeBook()

Folder = "c:\temp\"

Set DestSheet = ActiveSheet
FName = Dir(Folder & "*.xls")
Do While FName < ""
LastRow = DestSheet.Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow + 1
Set OldBook = Workbooks.Open(Filename:=Folder & FName)
With OldBook.Sheets("Sheet1")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Rows("1:" & LastRow).Copy Destination:=DestSheet.Rows(NewRow)
End With
OldBook.Close savechanges:=False
FName = Dir()
Loop
End Sub

"drumbumuk" wrote:

I have about 40 xl files, that I want to merge - quickly! But i dont want to
import row one as this just contains field names.

Any suggestions?

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
Inserting text into numerous cells for many different files joshua Excel Discussion (Misc queries) 4 December 29th 06 06:09 PM
Help extract numerous text files and how to use avg formula [email protected] Excel Worksheet Functions 0 May 16th 06 11:38 PM
Extracting cell data from numerous files in multiple folders???? JoeJoe Excel Worksheet Functions 5 March 23rd 06 03:10 AM
Merging Different excel files into one Neill Excel Discussion (Misc queries) 0 October 27th 05 09:15 PM
merging my excel files Donna YaWanna Excel Discussion (Misc queries) 1 June 14th 05 12:53 AM


All times are GMT +1. The time now is 12:28 AM.

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"