+ Reply to Thread
Results 1 to 4 of 4

Macro to combine same-named sheets from multiple files

Hybrid View

  1. #1
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Macro to combine same-named sheets from multiple files

    Hi All,

    I have 30 files in one folder, each of these files has 6 tabs identically named: dog, cat, bird, fish, fly, ape. I wish to combine only the ‘cat’ sheet from all 30 files into a single file, with the sheets renamed to cat1, cat2, cat3,…cat30 (or some sequential naming order)

    Thank you in advance

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to combine same-named sheets from multiple files

    Put this macro in a new spreadsheet.
    Save it in the folder
    open it
    Stand Back


    Sub Auto_Open()
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim i As Integer
    
    MyPath = ActiveWorkbook.Path
    
    MyName = ActiveWorkbook.Name
    
    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Get the folder object
    Set objFolder = objFSO.GetFolder(MyPath)
    
    Count = 0
    For Each objFile In objFolder.Files
    Temp = objFile.Name
    If Right(objFile.Name, 5) = ".xlsx" Then
        
    ChDir MyPath
    Workbooks.Open Filename:=objFile.Name
    count = count +1
        Sheets("Cat").Move After:=Workbooks(MyName).Sheets(Workbooks(MyName).Sheets.count)
        ActiveSheet.Name ="Cat-" & Count
        Windows(objFile.Name).Close False
    
    End If
    
    Next objFile
    
    End Sub

  3. #3
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to combine same-named sheets from multiple files

    o..m..G!

    My hero! This is fantastic! I've tried 20 macros today and none worked - your is flawless - cats everywhere! BIG THANKS

  4. #4
    Registered User
    Join Date
    09-04-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to combine same-named sheets from multiple files

    o..m..G!

    My hero! This is fantastic! I've tried 20 macros today and none worked - your is flawless - cats everywhere! BIG THANKS

+ 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. Vba/macro to combine multiple workbooks with multiple sheets into one workbook
    By ReshayM in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-03-2015, 01:00 PM
  2. Replies: 2
    Last Post: 09-19-2013, 04:22 AM
  3. Macro to combine and clean multiple files
    By micahjb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 07:16 PM
  4. [SOLVED] Need a macro to combine multiple cells in different sheets (Concatinate)
    By kishoremcp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 06:51 AM
  5. Replies: 7
    Last Post: 10-19-2011, 08:33 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