You are here:

Excel/Consolidation Macro Problem with different sheet names



Could you please suggest me a macro that pulls particular data from different sheets and paste it in a single sheet. I have macro for consolidation but there is a problem. We will get report from market every week. So we need to consolidate the data manually.  The sheet name and sheet count will differ (Eg: this week we may get 10 sheets with some name and next week 13 sheets with some other names) all the time.
So I could not able to prepare a macro to pull the data. Kindly suggest me a macro to resolve this issue. Thank you.

ANSWER: If this is simply a macro to open each file and pull the data onto one main sheet, then it's a relatively simple process.  The steps are
for every file in the folder
for every worksheet in the file
copy the data to the storage file on the first blank row
repeat until done

I can write a macro for you if needed.

---------- FOLLOW-UP ----------

Consolidation Macro
Consolidation Macro  

Could you please suggest me a consolidation macro. We will receive the weekly report with 50-60 pages. In each Sheet, contents remains same as shown in the image. But the problem is, each week, the sheet name will change and sheet count will also change (for example if this week, I have received report with 56 sheets, next week it may differ as 53 sheets or 58 sheets etc). So I could not able to make a consolidation macro.

Kindly suggest me a macro to consolidate the content from different sheets to one main sheet (in another excel). Thank you in advance.

With Regards,

Sub importdata()
Dim NewBook As Workbook, CurBook As Workbook
Dim OutVar As Long
Dim Looper As Long
OutVar = 1
Set CurBook = ActiveWorkbook
Set NewBook = Workbooks.Add
For Each sh In CurBook.Sheets

   For Looper = 1 To sh.Cells.SpecialCells(xlCellTypeLastCell).Row
       NewBook.ActiveSheet.Cells(OutVar, 1).Value = sh.Cells(Looper, 1).Value
       NewBook.ActiveSheet.Cells(OutVar, 2).Value = sh.Cells(Looper, 2).Value
       NewBook.ActiveSheet.Cells(OutVar, 3).Value = sh.Cells(Looper, 3).Value
       OutVar = OutVar + 1

End Sub

This macro will create a new workbook and store data from the first three columns of each sheet in the workbook that was active when the macro was run.
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


All Answers

Answers by Expert:

Ask Experts


Aidan Heritage


I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!


My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2017 All rights reserved.