You are here:

Excel/Combine multiple tables/spreadsheets

Advertisement


Question
Hi,

I have over 25 excel tables, each table has at least 15 sheets and I need to find a way to combine different sheets from those different tables into a new single table. Is it even possible?
I DO NOT want to consolidate and bring total dollar amounts from those tables.
Is there any way I can do that with a formula, macro, function or anything else besides the time consuming copy/paste function ?

Thanks in advance
Gabriel

Answer
Hi Gabriel,

This can only be done easily using a macro.
The code below assumes you have a worksheet called "AllData" and opens all files you select, copies all content of all sheets into that worksheet:

Sub GetOpenFileNameExample3()
   Dim lCount As Long
   Dim vFileName As Variant
   Dim sPath As String
   Dim lFilecount As Long
   sPath = "c:\windows\temp\"
   ChDrive sPath
   ChDir sPath
   vFileName = Application.GetOpenFilename("Microsoft Excel files (*.xls*),*.xls*", , "Please select the file(s) to open", , True)
   If TypeName(vFileName) = "Boolean" Then Exit Sub
   For lCount = LBound(vFileName) To UBound(vFileName)
       ProcessFile CStr(vFileName(lCount))
   Next
End Sub


Sub ProcessFile(sFileName As String)
   Dim oSh As Worksheet
   Workbooks.Open sFileName
   For Each oSh In Worksheets
       oSh.UsedRange.Copy
       With ThisWorkbook.Worksheets("AllData")
         .Range("A" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
       End With
   Next
   ActiveWorkbook.Close False
End Sub

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.