PDA

View Full Version : Copy data from multiple workbooks into separate tabs



jet
08-27-2013, 08:48 PM
This is great information. Is there a simple way to edit this to consolidate the worksheets into one workbook, creating a separate tab for each consolidated worksheet, instead of all data on one sheet? Thanks in advance...

bakerman
08-28-2013, 01:37 PM
What is great information ? A simple way to edit what ?
Before we can help you out you will have to give us some more information about what you want to achieve.

Admin
08-28-2013, 01:58 PM
Hi

Untested.


Option Explicit

Sub kTest()

Dim SourceFolder As String
Dim wbkSource As Workbook
Dim wbkDest As Workbook
Dim FName As String
Dim rngSource As Range
Dim wksDest As Worksheet

SourceFolder = "C:\Test" '<<< adjust the folder

If Right$(SourceFolder, 1) <> "\" Then SourceFolder = SourceFolder & "\"

FName = Dir(SourceFolder & "*.xls*")

Set wbkDest = ThisWorkbook
Application.ScreenUpdating = 0
Set wksDest = wbkDest.Worksheets(wbkDest.Worksheets.Count)

Do While Not FName = vbNullString
If Not FName = wbkDest.Name Then
Set wbkSource = Workbooks.Open(SourceFolder & FName, 0)
Set rngSource = wbkSource.Worksheets(1).Range("a1").CurrentRegion
Set wksDest = wbkDest.Worksheets.Add(, wksDest)
rngSource.Copy wksDest.Range("a1")
wksDest.Name = FName
End If
wbkSource.Close 0
Set wbkSource = Nothing
FName = Dir()
Loop
Application.ScreenUpdating = 1

End Sub

Admin
08-28-2013, 02:02 PM
What is great information ? A simple way to edit what ?
Before we can help you out you will have to give us some more information about what you want to achieve.

@ bakerman,
The OP was refering thread - http://www.excelfox.com/forum/f13/consolidate-multiple-workbooks-from-a-folder-into-one-master-file-vba-569/