+ Reply to Thread
Results 1 to 14 of 14

Merging multiple workbooks that contain identical tabs:Animal

Hybrid View

  1. #1
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Merging multiple workbooks that contain identical tabs:Animal

    I am looking to merge multiple workbooks that contain the same three tabs.

    Tabs:

    Animal
    Food
    Place
    Attached Files Attached Files
    Last edited by Heather.Taylor; 08-04-2011 at 01:34 PM.

  2. #2
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    re: Merging multiple workbooks that contain identical tabs:Animal

    Hi,

    Have a look here?

    http://www.excelforum.com/excel-prog...g-headers.html
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: Merging multiple workbooks that contain identical tabs:Animal

    'WORKBOOKS W/MULTIPLE SHEETS MERGED INTO SHEETS IN CONSOLIDATION WORKBOOK

    Here's a macro for collecting data from all sheets in all files in a specific folder merging into matching sheets.The parts of the code that need to be edited are colored to draw your attention.

    I'm pretty sure all you need to edit is the the fPath string to properly point to where your source files are located. Then edit the fName code to .xlsx.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    re: Merging multiple workbooks that contain identical tabs:Animal

    I tried that macro, but for some reason it doesn't go to that file path but it opens other random spreadsheets to copy over.

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    re: Merging multiple workbooks that contain identical tabs:Animal

    Hi Heather,

    Are you using this code? Can you post your changes to this code

    Option Explicit
     
    Sub ConsolidateSheetsFromWorkbooks()
    'Author:    Jerry Beaucaire, ExcelForum.com
    'Date:      1/5/2011
    'Summary:   Open all files in a folder and merge data (stacked) on all
    '           sheets into main wb matching the sheet names.
    '           Assumes all sheets with titles exist in main book and
    '           data sheets data starts at row 2
    Dim wbData As Workbook, wbMain As Workbook
    Dim wsMain As Worksheet, wsData As Worksheet
    Dim LR As Long, NR As Long
    Dim fPath As String, fName As String
     
    Set wbMain = ThisWorkbook
     
                                       'if files are stored in separate directory edit fPath
    fPath = ThisWorkbook.Path & "\"     'don't forget the final \
     
    fName = Dir(fPath & "*.xls")        'start looping through files one at a time
    Application.ScreenUpdating = False
     
        Do While Len(fName) > 0
            If fName <> ThisWorkbook.Name Then
                Set wbData = Workbooks.Open(fPath & fName)
                For Each wsData In wbData.Worksheets
                    Set wsMain = wbMain.Sheets(wsData.Name)
                    NR = wsMain.Range("A" & Rows.Count).End(xlUp).Row + 1
                    With wsData
                        LR = .Range("A" & .Rows.Count).End(xlUp).Row
                        .Range("A2:A" & LR).EntireRow.Copy wsMain.Range("A" & NR)
                    End With
                Next wsData
     
                wbData.Close False
            End If
     
            fName = Dir                 'queue up next filename
        Loop
     
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    re: Merging multiple workbooks that contain identical tabs:Animal

    Yes I am.

     
    Set wbMain = ThisWorkbook
     
                                       'if files are stored in separate directory edit fPath
    fPath =  "U:\2010\TEST\"     'don't forget the final \
     
    fName = Dir(fPath & "*.xlsx")        'start looping through files one at a time
    Application.ScreenUpdating = False
    Last edited by Heather.Taylor; 08-03-2011 at 11:00 AM.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: Merging multiple workbooks that contain identical tabs:Animal

    I'm no networking guru, but you changed to drive U: which sounds like a network drive to me. Perhaps that could be giving you issues. Do you know the network address of the same drive? Not the locally mapped version? That might work better.

    Look at my signature, it shows the proper way to wrap your code in tags. Please edit your post above to use the proper tags. You could also edit out all the code you didn't change since it's already posted in this thread...keep things tidy.

  8. #8
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    re: Merging multiple workbooks that contain identical tabs:Animal

    I changed the fpath to my desktop and it stops at this part of the macro.


    Set wsMain = wbMain.Sheets(wsData.Name)

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: Merging multiple workbooks that contain identical tabs:Animal

    When it stops and you DEBUG, hang your mouse over the wsData.Name variable and tell me what the current value is that appears.

  10. #10
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    re: Merging multiple workbooks that contain identical tabs:Animal

    wsData.Name = "Advance - Datacomm" (which is the first sheets name on my spreadsheets)

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: Merging multiple workbooks that contain identical tabs:Animal

    So, the problem is occurring when the macro tries to set the wsMain sheet variable to the sheet Sheets("Advance - Datacomm") in the workbook that is your wbMain, there is something not matching exactly. This is usually hidden spaces or something like that...

  12. #12
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Adding macro in the middle of a created macro

    "nevermind"
    Last edited by Heather.Taylor; 08-04-2011 at 01:32 PM.

  13. #13
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    re: Merging multiple workbooks that contain identical tabs:Animal

    "nevermind"
    Last edited by Heather.Taylor; 08-04-2011 at 01:33 PM.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: Merging multiple workbooks that contain identical tabs:Animal

    Just edit the post above and delete the content, replace it with a "nevermind" comment.

    Then go to post #1... click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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