Results 1 to 34 of 34

Thread: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

  1. #1
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Resolved [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    Hi everybody,
    I have 6 excel workbooks each with 193 sheets. Format of all the workbooks is same with the same sheet names. I want to append the data of all the 6 workbooks into one workbook just like sheet1 of workbook1 would have the original data of sheet1 of workbook1 then in the very next empty available row paste the data of sheet1 of workbook2 then sheet1 of workbook3 and so on till sheet1 of workbook6, same for the sheet2 , sheet3....................sheet193.

    I wrote this code it is working but it does not paste by maintaining the sequence (Problem is it sometimes paste the sheet3 of workbook2 into the sheet1 of workbook1 but by desire it should paste the sheet1 of workbook2 into the sheet1 of workbook1)

    All six Workbook names are:
    HYD15.xls
    HYD16.xls
    HYD17.xls
    HYD18.xls
    HYD19.xls
    HYD20.xls


    I am appending HYD16.xls and HYD17.xls into HYD15.xls (kindly help)
    Code:
    Sub append_test()
        
        For Index = 1 To 193
        
        Windows("HYD16.xls").Activate
        Worksheets(ActiveSheet.Index).Activate
        lastCol = ActiveSheet.Range("a6").End(xlToRight).Column
        lastRow = ActiveSheet.Cells(65536, lastCol).End(xlUp).Row
        ActiveSheet.Range("a6:" & _
        ActiveSheet.Cells(lastRow, lastCol).Address).Select
        Selection.Copy
        Windows("HYD15.xls").Activate
        Worksheets(ActiveSheet.Index).Activate
        NextRow = Range("A65536").End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Worksheets(ActiveSheet.Index + 1).Activate
        
        Next Index
        For Index = 1 To 193
        
        Windows("HYD16.xls").Activate
        Worksheets(ActiveSheet.Index).Activate
        lastCol = ActiveSheet.Range("a6").End(xlToRight).Column
        lastRow = ActiveSheet.Cells(65536, lastCol).End(xlUp).Row
        ActiveSheet.Range("a6:" & _
        ActiveSheet.Cells(lastRow, lastCol).Address).Select
        Selection.Copy
        Windows("HYD15.xls").Activate
        Worksheets(ActiveSheet.Index).Activate
        NextRow = Range("A65536").End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Worksheets(ActiveSheet.Index + 1).Activate
        
        Next Index
    
    End Sub
    Last edited by Hack; Jul 17th, 2012 at 11:22 AM. Reason: Added Code Tags

  2. #2
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,942

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    3 threads for the same question?

  3. #3
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    yeah because its very very very urgent.

  4. #4
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,942

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Starting several threads will not help. Never start more than 1 thread per question.

    Why on earth would anyone have 193 sheets in an Excel workbook!

    To locate your problem, set a breakpoint and step through your code to see what is going wrong.

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,283

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    I will thank you to watch both your language and your attitude.

    Verbal abuse will not be tolerated.

    I have deleted the duplicate threads you created as well as the duplicate post in this thread.

    Do not create duplicates for the same question and do not bump your own threads. Your questions will be addressed as the individuals (all volunteers) have the time to do so.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  6. #6
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,520

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    I wrote this code it is working but it does not paste by maintaining the sequence (Problem is it sometimes paste the sheet3 of workbook2 into the sheet1 of workbook1 but by desire it should paste the sheet1 of workbook2 into the sheet1 of workbook1)
    most probably this is because you are working with active sheet and other none specific objects, you should fully qualify each sheet object to prevent this type of error

    yeah because its very very very urgent.
    i ignored this thread last night as i saw 3 copies of same
    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

  7. #7
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    vbakillsnuts

    Welcome to the forums

    The simplest way to do this would be to declare your objects Ex: Workbooks, Worksheets etc. This would help you easily work with them. Also avoid
    Code:
    .Select
    and .
    Code:
    .Activate
    as they are a major cause of errors besides making your macro very slow.

    This is what I propose.

    Create a New workbook and then insert a module there. Paste this code. This code will insert 193 sheets in the current workbook and merge data from all the sheets from all 6 workbooks. Please note that I have not tested it so do let us know if you get stuck

    I have also commented the code so you will not have any problem understanding it. The current code is designed to work with only 2 workbooks but I have left instructions on how to add the code for the other 4. Remember to change the code to suit your needs before you test it.

    Code:
    Sub Sample()
        Dim wb1 As Workbook, wb2 As Workbook, wb3 As Workbook, wb4 As Workbook, wb5 As Workbook, wb6 As Workbook
        Dim ws As Worksheet
        Dim i As Long, wsLRow As Long
        
        '~~> Change path as applicable
        Set wb1 = Workbooks.Open("C:\HYD15.xls")
        Set wb2 = Workbooks.Open("C:\HYD16.xls")
        Set wb3 = Workbooks.Open("C:\HYD17.xls")
        Set wb4 = Workbooks.Open("C:\HYD18.xls")
        Set wb5 = Workbooks.Open("C:\HYD19.xls")
        Set wb6 = Workbooks.Open("C:\HYD20.xls")
        
        '~~> This will copy all 193 sheets into the current workbook from HYD15
        wsLRow = 1
        For i = 1 To 193
            Set ws = ThisWorkbook.Sheets.Add
            ws.Name = wb1.Sheets(i).Name
            CopyFrom wb1.Sheets(i), ws, wsLRow
        Next
        
        '~~> This will copy all 193 sheets into the current workbook from HYD16
        For i = 1 To 193
            '~~> no Need to add new sheet. use the already created sheets
            Set ws = ThisWorkbook.Sheets(wb2.Sheets(i).Name)
            
            '~~> Find the next empty row
            wsLRow = ws.Cells.Find(What:="*", _
                              After:=ws.Range("A1"), _
                              Lookat:=xlPart, _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious, _
                              MatchCase:=False).Row + 1
            
            CopyFrom wb2.Sheets(i), ws, wsLRow
        Next
        
        '
        ' ~~> Similarly copy the other sheets
        '
    End Sub
    
    '~~> Common Sub that you can use to do the actual copying and pasting
    Sub CopyFrom(wstInpt As Worksheet, wstOutpt As Worksheet, wsLastRow As Long)
        Dim lRow As Long
        
        '~~> Get Last Row of .Sheets(i)
        With wstInpt
            If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
                lRow = .Cells.Find(What:="*", _
                              After:=.Range("A1"), _
                              Lookat:=xlPart, _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious, _
                              MatchCase:=False).Row
            Else
                lRow = 1
            End If
            
            .Rows("1:" & lRow).Copy wstOutpt.Rows(wsLRow)
        End With
    End Sub
    HTH
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  8. #8
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Thread moved

  9. #9
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Koolsid
    Thanks for your support. when i run your code the following error occurs:
    Run-time error '1004'
    application-defined or object-defined error


    When i click on the debugg this highlight the line with error. For both the snapshots are attached.
    Attached Images Attached Images   

  10. #10
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,520

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    maybe it should be
    vb Code:
    1. .Rows("1:" & lRow).Copy wstOutpt.Rows(wsLastRow)
    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

  11. #11
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    @Pete: Nice Catch
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  12. #12
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Dear Koolsid and Westconn1:
    Thank you so much guys, your suggested code is working now but there are few things remaining,
    1. The code pastes the sheets in reverse order for example the first sheet in HYD15.xls/HYD16.xls is now the last sheet of the appended sheet and similarly last sheet is the first. sheet order is reversed but the data appended in these are fine.
    2.Each sheet contains headers and then the data below the headers, your code pastes the whole sheet. But desired workbook should be the one displayed in snapshot.

    There are four snapshots attached:
    -One displays the data of the sheet 2 of HYD15.xls
    -Second displays the data of the sheet 2 of HYD16.xls
    -Third displays the data appended by your code
    -Fourth displays the desired data.
    Name:  hyd15.png
Views: 58
Size:  11.9 KB

    Name:  hyd16.png
Views: 53
Size:  13.4 KB

    Name:  code format.png
Views: 56
Size:  25.1 KB

    Name:  desired format.png
Views: 56
Size:  19.8 KB

    BTW You guys are the kings of vba.Thaks alot. I know that was my mistake i couldn't present the desired workbook in right way. Thanks alot man.

  13. #13
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Clue

    See this code in the function. What do you think this does

    Code:
    .Rows("1:" & lRow).Copy wstOutpt.Rows(wsLRow)
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  14. #14
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Dear Koolsid,
    I am still confused, I changed the row number in the above mentioned code line but still can't get that.
    Name:  header problem.png
Views: 54
Size:  19.6 KB

    Another Problem is:
    Name:  two header sheets.png
Views: 56
Size:  21.9 KB

  15. #15
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    The two header sheet displaying in the above snapshot is present in both original sheets i.e. HYD16.xls and HYD15.xls. Kindly suggest the solution.

  16. #16
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    The first time you copy, the code

    .Rows("1:" & lRow).Copy wstOutpt.Rows(wsLRow)

    remains unchanged. Next time onwards you change it to

    .Rows("6:" & lRow).Copy wstOutpt.Rows(wsLRow)

    The best way is to check if the output sheet has any data. If the output sheet doesn't have any data then you use 1 else use 6
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  17. #17
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Okay and for two headers sheets?

  18. #18
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    That could pose a problem. But then you can always check if Col 1 as "UL Assignment" or "BSC Name" and ignore/delete them?

    1. You can do that either by first looping though all the sheets and deleting the rows after row 6 which has these two words and then importing the rest of the data or

    2. You can import everything and then in the end and then loop though all the sheets and delete the rows after row 6 which has these two words.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  19. #19
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    I am using this code to find out if the current sheet is empty so that i can use row 1 if not empty then row 6. Error occurs object required.
    Can u please debugg this?

    vb Code:
    1. If Not wsOutpt.GetBottomRow = 0 Then
    2.        
    3.         .Rows("1:" & lRow).Copy wstOutpt.Rows(wsLastRow)
    4.         Else
    5.         .Rows("6:" & lRow).Copy wstOutpt.Rows(wsLastRow)
    6.         End If

  20. #20
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Change

    Code:
    If Not wsOutpt.GetBottomRow = 0 Then
    to

    Code:
    If wsLastRow = 1 then
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  21. #21
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Thank you so man. that was very helpfull.
    only one thing left now
    sheet sequence
    Name:  original sheet sequency.png
Views: 54
Size:  9.1 KB

    Name:  output sheet sequency.png
Views: 55
Size:  11.2 KB

  22. #22
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Change this line

    Code:
    Set ws = ThisWorkbook.Sheets.Add
    to

    Code:
    Set Ws = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
    Try now.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  23. #23
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    OMG!! This is perfect, u're amazing coder
    I am really sorry there is 1 more problem
    Error:
    Subscritp out of range occurs at:

    Name:  subscript out of range.png
Views: 55
Size:  16.3 KB

  24. #24
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    and by this last 2 sheets cannot be appended. Output sheet does not contain the last 2 sheets of the original sheets.

  25. #25
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    What is the value of i?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  26. #26
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Resolved Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Total sheets in orignal workbook is 193, but when i changed the value of "i" as 195 now the same error occurs but sheets are appended as well


    Thank you so much koolsid

  27. #27
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Append 2 or more workbooks of multiple sheets into a single workbook

    Glad to be of Help

    If you have JavaScript enabled you can mark the thread resolved by selecting the Mark Thread Resolved item from the Thread Tools menu. Otherwise please insert [Resolved] at the start of the Subject and select the green check mark from the post icons. You may also visit the FAQ to see the snapshots on how it works.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  28. #28
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    @Koolsid:
    the error mentioned above(i.e. subscript out of range) is still occuring now I have i = 197. It appends complete first two sheets (e.g HYD15.xls & HYD16.xls) and then raise this error, untill I get rid of this error I will not be able to append 3rd, 4th, 5th and 6th sheet.

    when I raise the value of i to 198 it gives another error relating to sheet name at the code line
    Code:
    ws.Name = wb1.Sheets(i).Name
    can you fix this issue too?

  29. #29
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    Can you please confirm if all the workbooks have same number of sheets?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  30. #30
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    number of sheets are not equal in all the workbooks. only difference of 1 or 2 sheets. some workbooks have title sheet in start n help sheet in the end n some don't have. when i deleted title and help sheet from all the workbooks, error still occurs.

  31. #31
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    IF

    1) All the Workbooks have same number of sheet and
    2) i matches the total number of sheets then you will not get an error.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  32. #32
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    is there any way to change the range of i automatically according to workbook?

  33. #33
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    Change this

    Code:
    For i = 1 To 193
    to

    Code:
    For i = 1 To wb1.Sheets.Count
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  34. #34
    Junior Member
    Join Date
    Jul 12
    Posts
    16

    Resolved Re: [RESOLVED] Append 2 or more workbooks of multiple sheets into a single workbook

    Perfect

    Thank you so much koolsid.

Posting Permissions

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