+ Reply to Thread
Results 1 to 11 of 11

Macro to consolidate data from many files

Hybrid View

Masa1989 Macro to consolidate data... 01-13-2015, 03:15 AM
Masa1989 Re: Macro to consolidate data... 01-13-2015, 09:15 AM
marreco Re: Macro to consolidate data... 01-13-2015, 09:33 AM
Masa1989 Re: Macro to consolidate data... 01-13-2015, 12:44 PM
ayushjohnian Re: Macro to consolidate data... 01-13-2015, 10:13 AM
ayushjohnian Re: Macro to consolidate data... 01-13-2015, 10:15 AM
Masa1989 Re: Macro to consolidate data... 01-13-2015, 12:46 PM
Masa1989 Re: Macro to consolidate data... 01-13-2015, 12:47 PM
Masa1989 Re: Macro to consolidate data... 01-13-2015, 01:03 PM
Masa1989 Re: Macro to consolidate data... 01-14-2015, 01:59 AM
Masa1989 Re: Macro to consolidate data... 01-15-2015, 07:56 AM
  1. #1
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Macro to consolidate data from many files

    Greetings,

    I need a macro that gathers information from 3 different workbooks and consolidates it on one master file

    Each of the three workbook has 6 different sheets, and same named and layout sheets are there in master workbook file as well

    Basically what i need is sum of the 3 files respective sheets data in to master file same named sheet in the same cells

    Eg

    Workbook 1 has sheet 1, sheet 2, sheet 3 , sheet 4, sheet 5, sheet 6
    Workbook 2 has sheet 1, sheet 2, sheet 3 , sheet 4, sheet 5, sheet 6
    Workbook 3 has sheet 1, sheet 2, sheet 3 , sheet 4, sheet 5, sheet 6

    Master has sheet 1, sheet 2, sheet 3 , sheet 4, sheet 5, sheet 6

    what i want is in master file sheet 1( sum of same cells from sheet 1 from workbook 1, sheet 1 from workbook 2 and sheet 1 from workbook 3),sheet 2( sum of same cells from sheet 2 from workbook 1, sheet 2 from workbook 2 and sheet 2 from workbook 3),sheet 3( sum of same cells from sheet 3 from workbook 1, sheet 3 from workbook 2 and sheet 3 from workbook 3),sheet 4( sum of same cells from sheet 4 from workbook 1, sheet 4 from workbook 2 and sheet 4 from workbook 3),sheet 5( sum of same cells from sheet 5 from workbook 1, sheet 5 from workbook 2 and sheet 5 from workbook 3)



    I will be eternally grateful if anyone can help me crack this!

  2. #2
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    Can anyone help me out please?

  3. #3
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Macro to consolidate data from many files

    Hi
    try...
    http://chandoo.org/wp/2012/04/09/con...cel-files-vba/
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  4. #4
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    @ Marecco, hat doent give me desired result, it gives result from only one sheet and doesnt even add up in master file

  5. #5
    Registered User
    Join Date
    02-20-2013
    Location
    bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to consolidate data from many files

    You would require a nested loop of 3 loops, 1. for Master file - for each sheet run a loop 2. For all workbooks. 3. each sheet in selected workbook.

    when it is innermost loop, use the loop(sheet) value of Master making equal to sheet of other workbooks.

    Otherwise simply open all workbooks, write down formula in each sheet "=W1.sheet1!A1+W2.sheet1!A1+W2.sheet1!A1" (Something like that) and drag till your desired range. do the same for all sheets.

  6. #6
    Registered User
    Join Date
    02-20-2013
    Location
    bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to consolidate data from many files

    You would require a nested loop of 3 loops, 1. for Master file - for each sheet run a loop 2. For all workbooks. 3. each sheet in selected workbook.

    when it is innermost loop, use the loop(sheet) value of Master making equal to sheet of other workbooks.

    Otherwise simply open all workbooks, write down formula in each sheet "=W1.sheet1!A1+W2.sheet1!A1+W2.sheet1!A1" (Something like that) and drag till your desired range. do the same for all sheets.

  7. #7
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    @ Ayush, can u give me a sample structure of the macro,?

    when i use normal ="=W1.sheet1!A1+W2.sheet1!A1+W2.sheet1!A1" my file goes beyond 35mb, so i want to use macro to copy and later paste as values to keep file size low as possible

  8. #8
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    @ Ayush, can u give me a sample structure of the macro,?

    when i use normal ="=W1.sheet1!A1+W2.sheet1!A1+W2.sheet1!A1" my file goes beyond 35mb, so i want to use macro to copy and later paste as values to keep file size low as possible

  9. #9
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    Sub cons_data()
    
    Dim Master As Workbook
    Dim sourceBook As Workbook
    Dim sourceData As Worksheet
    Dim sourceSheet As Worksheet
    Dim CurrentFileName As String
    Dim myPath As String
    Dim sname As String
    
    Application.ScreenUpdating = False
    
    myPath = "D:\trial"                    'The folder containing the files to be combined
    
    CurrentFileName = Dir(myPath & "\*.xls")    'Finds the name of the first file of type .xls in the current directory
    
    Set Master = ThisWorkbook                   'Create a workbook for the recap report
    
    Do
        Workbooks.Open (myPath & "\" & CurrentFileName)
        Set sourceBook = Workbooks(CurrentFileName)
        
        For Each sourceSheet In sourceBook.Worksheets
          Set sourceData = sourceSheet
        
          With sourceData
                With sourceSheet
              sname = Left(CurrentFileName, Len(CurrentFileName) - 4) & Format(.Index, "000")
              .Copy After:=Master.Worksheets(Master.Worksheets.Count)
              ActiveSheet.Name = sname
          End With
           
              Master.Worksheets.Add(After:=Master.Worksheets(Master.Worksheets.Count)).Name = sname
              .Cells.Copy Master.Worksheets(sname).Range("A1")
          End With
           
        Next
        
        sourceBook.Close
      
        'Calling DIR w/o argument finds the next xls file within the current directory.
        CurrentFileName = Dir()
    
    Loop While CurrentFileName <> ""
    
    Application.ScreenUpdating = True
    
    End Sub

    does this structure suit my requirement, it gets get run time error whenever i run it

  10. #10
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    range to be copied is i13:pf1162, all three files saved in one folder say D:new\segments, the master file is also present in the same folder

    Can anyone help on this please?

  11. #11
    Forum Contributor
    Join Date
    12-11-2014
    Location
    dubai
    MS-Off Ver
    2010
    Posts
    142

    Re: Macro to consolidate data from many files

    Can anyone throw some light on this please????

+ 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. [SOLVED] How to adapt the macro to allow it to consolidate files with multiple sheets?
    By billj in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-04-2013, 05:18 PM
  2. need macro to consolidate data from .xml files.
    By sekharyadav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 11:03 AM
  3. Macro to consolidate the data from mutliple files using Vlookup / Match
    By pradeepkodali in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2012, 01:46 PM
  4. Macro to consolidate data from many files
    By annasox in forum Excel General
    Replies: 5
    Last Post: 01-17-2011, 12:32 PM
  5. Macro to oepn multiple txt files and then consolidate
    By Nonboff in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-26-2009, 09:44 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