+ Reply to Thread
Results 1 to 12 of 12

VBA Code to consolidate sheets from multiple workbooks into one workbook

  1. #1
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    VBA Code to consolidate sheets from multiple workbooks into one workbook

    Hi All,
    I have Workbook 1, but I am trying to combine one sheet from Workbook 2 and one sheet from Workbook 3 into Workbook 1 with one simple macro..

    Can anyone help me?

    This is what I have so far which does one sheet from Workbook 2 fine, but how can I repeat the steps and also merge one sheet from Workbook 3 with the same macro?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Try this out adjust to suite.
    Please Login or Register  to view this content.
    http://www.davesexcel.com/vbacodes.htm#858298827
    Last edited by davesexcel; 12-10-2014 at 01:24 AM.

  3. #3
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Quote Originally Posted by davesexcel View Post
    Try this out adjust to suite.
    Please Login or Register  to view this content.
    http://www.davesexcel.com/vbacodes.htm#858299473
    This works perfectly for 1 sheet from 1 workbook, how would I repeat the process to pull a 2nd sheet from a 2nd workbook (all in the same macro?)

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Did you try it?
    Do you want both sheets in the same worksheet in workbook 1?

  5. #5
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    I want to be able to pull sheets from multiple workbooks into my original workbook (that contains that macro).
    I tried it, and it pulls 1 sheet from 1 workbook into my original file - how would I repeat the process to pull another sheet from a different workbook...?

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    The code loops through the folder, it opens each workbook in the folder, does it's stuff, then closes the workbook and opens the next workbook.

  7. #7
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    I'm getting a subscript out of range error..

  8. #8
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Quote Originally Posted by d247 View Post
    This works perfectly for 1 sheet from 1 workbook, how would I repeat the process to pull a 2nd sheet from a 2nd workbook (all in the same macro?)
    Where it says CC-INFO - am I supposed to change that with my sheet name?

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Did you change the folder names, and sheet names?

  10. #10
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Quote Originally Posted by davesexcel View Post
    Did you change the folder names, and sheet names?
    This is what I put... Where do I put the two sheet names?
    The workbooks are called Sales, and Marketing... The sheets inside are just Sales1, Marketing1 Respectively.

    [CODE]]Sub LoopThroughFolder()
    Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook, bk As Workbook
    Dim Rws As Long, Rng As Range

    Set Wb = ThisWorkbook
    'change the address to suite
    MyDir = "C:\Users\X\"
    MyFile = Dir(MyDir & "*.xlsx") 'change file extension
    ChDir MyDir

    Application.ScreenUpdating = 0
    Application.DisplayAlerts = 0

    Do While MyFile <> ""
    Workbooks.Open (MyFile)
    Set bk = ActiveWorkbook
    Sheets("CC-INFO").Copy Before:=Wb.Sheets(1) 'use your sheet variable
    bk.Close True

    Application.DisplayAlerts = 1
    MyFile = Dir()

    Loop

    End Sub[/CODE

  11. #11
    Registered User
    Join Date
    12-19-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    Quote Originally Posted by davesexcel View Post
    Did you change the folder names, and sheet names?
    Any ideas?

  12. #12
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VBA Code to consolidate sheets from multiple workbooks into one workbook

    I would do it this way.
    Please Login or Register  to view this content.

+ 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] Consolidate all sheets across multiple workbooks
    By AndrewSimpson87 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-10-2015, 12:01 PM
  2. 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
  3. VBA for consolidate sheets into one workbook from list of workbooks.
    By sureshpunna in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2013, 07:13 AM
  4. [SOLVED] Consolidate data from multiple workbooks into 1 workbook
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 12-17-2012, 01:11 PM
  5. Need to Consolidate multiple workbooks in to a Master Workbook w/ files on SharePoint
    By newbietoVBA in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2012, 11:30 PM

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