Results 1 to 26 of 26

Thread: [RESOLVED] [MS Excel 2010] Consolidating all 55 workbooks into 1 new workbook

Threaded View

  1. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [MS Excel 2010] Consolidating all 55 workbooks into 1 new workbook

    does it matter what order the workbook data is entered into the consolidated book?
    the order, would be the same as the 55 workbooks are opened
    if so some change would be required to sort the order of opening the workbooks

    Is it possible to develop a macro to do these tasks?
    entry level
    Code:
    Dim shts(2)
    Dim rw(2) As Long
    mypath = "C:\Consolidation\"
    Set newb = Workbooks.Add
    shts = Array("Total Consolidation", "State level Consolidation", "District Level Consolidation")
    'assumes new Workbook will contain 3 sheets by default, if not some sheets will have to be added
    newb.Sheets(1).Name = shts(0)
    newb.Sheets(2).Name = shts(1)
    newb.Sheets(3).Name = shts(2)
    rw(0) = 1
    rw(1) = 1
    rw(2) = 1
    fname = Dir(mypath & "*.xls")
    Do While Len(fname) > 0
      Set Wb = Workbooks.Open(mypath & fname)
      For s = 0 To 3
        rws = Wb.Sheets(shts(s)).UsedRange.Rows.Count
        cols = Wb.Sheets(shts(s)).UsedRange.Columns.Count
        newb.Sheets(shts(s)).Range("a" & rw(s)).Resize(rws, cols).value = Wb.Sheets(s).UsedRange.value
        rw(s) = rw(s) + rws
      Next
      Wb.Close False
      fname = Dir
    Loop
    newb.SaveAs mypath & "COUNTRY LEVEL CONSOLIDATION.xls"
    newb.Close  ' or omit if you want left open
    this is untested and may contain errors


    nobody is going to do it for you, your going to have to learn it.
    it is sunday and i am bored, but i hope you will at least study the code and make whatever modifications are necessary
    Last edited by westconn1; Jan 11th, 2014 at 06:24 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width