+ Reply to Thread
Results 1 to 6 of 6

Consolidate multiple workbook data into master workbook data - Reg.

  1. #1
    Forum Contributor
    Join Date
    08-19-2016
    Location
    Chennai, India
    MS-Off Ver
    2007
    Posts
    300

    Consolidate multiple workbook data into master workbook data - Reg.

    Dear Forum Experts,

    Kindly guide me for the following requirements.

    Requirements: - I want to consolidate data from 100 workbooks into master workbook along with headers and column indicators.

    Example: each workbooks contains the structure of table

    Particulars Qty-1 Qty-2 Qty-3

    A company 10 20 15
    B company 05 15 20
    C company 08 10 15

    Scenario:

    Each excel Workbook contains: 8 worksheets (MPR_Sec1, MPR_Sec2, MPR_Sec3......) and likewise 100 workbooks
    Database folder pathway: "C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\KL-MPR.xlsx"
    Master consolidation workbook has been placed: "C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation"
    Master Data Sheet (Consolidation) also contains 8 worksheets,

    I want to consolidate 100 workbooks MPR_Sec1 data in Master workboob MPR_Sec1 sheet. I have used the following code and Run-time error -9 Subscript out of range error popups in "Windows("National-MPR-Consolidation").Activate" consolidation data.


    Sub consolidateData()
    Range("B2").Select
    ActiveCell.Value = "Indicator No."
    Range("C2").Select
    ActiveCell.Value = "S.No"
    Range("D2").Select
    ActiveCell.Value = "Indicator Name"
    Range("E2").Select
    ActiveCell.Value = "Variable Type"
    Range("F2").Select
    ActiveCell.Value = "Source of Data"
    Range("B3").Select
    ActiveCell.Value = "A"
    Range("C3").Select
    ActiveCell.Value = "S.No"
    Range("D3").Select
    ActiveCell.Value = "Site Specific Information"
    Range("G3").Select
    ActiveCell.Value = "April"
    Range("B4").Select
    ActiveCell.Value = "A(i)"
    Range("C4").Select
    ActiveCell.Value = "S.No"
    Range("D4").Select
    ActiveCell.Value = "Govt and PPP"
    Range("G4").Select
    ActiveCell.Value = "SA-ICTC"
    Range("H4").Select
    ActiveCell.Value = "F-ICTC"
    Range("I4").Select
    ActiveCell.Value = "PPP-FICTC"
    Range("J4").Select
    ActiveCell.Value = "3 Test PPP"
    Range("K4").Select
    ActiveCell.Value = "Total"
    Range("C5").Select
    ActiveCell.Value = "1"
    Range("D5").Select
    ActiveCell.Value = "No. of facilities in the program till last month"
    Range("G5").Select
    Workbooks.Open Filename:="C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\KL-MPR.xlsx"
    Workbooks.Open Filename:="C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\PY-MPR.xlsx"
    Workbooks.Open Filename:="C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\TN-MPR.xlsx"
    Windows("National-MPR-Consolidation").Activate
    Selection.Consolidate Sources:=Array( _
    "'C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\[KL-MPR.xlsx]MPR_Sec1'!R5C7:R5C7", _
    "'C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\[PY-MPR.xlsx]MPR_Sec1'!R5C7:R5C7", _
    "'C:\Users\MAHI\Desktop\Others\MPR\National_MPR_Consolidation\DataBase_MPR\[TN-MPR.xlsx]MPR_Sec1'!R5C7:R5C7"), Function:=xlSum
    Windows("KL-MPR.xlsx").Activate
    ActiveWorkbook.Close
    Windows("PY-MPR.xlsx").Activate
    ActiveWorkbook.Close
    Windows("TN-MPR.xlsx").Activate
    ActiveWorkbook.Close
    End Sub
    Kindly do the needful.

    Regards

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Consolidate multiple workbook data into master workbook data - Reg.

    Hi, I just did a quick reading of your code, but you cannot activate a closed workbook.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    08-19-2016
    Location
    Chennai, India
    MS-Off Ver
    2007
    Posts
    300

    Re: Consolidate multiple workbook data into master workbook data - Reg.

    Dear Keebellah,

    Based on your suggestion, i have tried out and remove workbook close function and again facing same issue. Kindly do the needful.

    Regards

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Consolidate multiple workbook data into master workbook data - Reg.

    Try this
    Don't know if it works
    Else you will have to step though the code line by line and see where it stops. Maybe an incorrect reference but you have the data to test it

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-19-2016
    Location
    Chennai, India
    MS-Off Ver
    2007
    Posts
    300

    Re: Consolidate multiple workbook data into master workbook data - Reg.

    Great Keebellah,

    Works perfect and thanks a lot. What is the logic?

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Consolidate multiple workbook data into master workbook data - Reg.

    The source workbook is the one you need to return the focus to.
    My experience has been that the Windows("bla bla xlsx") activate doens't work since Office 2010
    This is because Excel can open a workbook in a different session which is no longer recognized after you open one or more extra workbooks, which I am assuming happened here.

    I always store the ActiveWorkbook in a variable, in this case myWorkBook so that Excel 'knows' what it's looking for.

    I hope I was able to explain my thoughts, it's easier to do than explain

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy the Data from Multiple workbook to Master Workbook as Conslidated
    By venugosr in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-19-2017, 01:32 AM
  2. Replies: 1
    Last Post: 12-15-2016, 04:26 AM
  3. Consolidate Multiple Workbooks With Same Column Header into 1 Master Workbook
    By markusvirus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-21-2016, 02:55 PM
  4. Replies: 12
    Last Post: 07-29-2014, 01:06 PM
  5. VBA to consolidate specific data from multiple workbooks to a master workbook
    By Blastaway12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2014, 04:39 PM
  6. [SOLVED] Consolidate Data from 1 Range on 1 Sheet in Multiple Workbooks to Master Workbook Sheet
    By Jennasis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2013, 06:11 AM
  7. Consolidate data from specific workbook to master workbook
    By greenbr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2010, 11:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1