+ Reply to Thread
Results 1 to 11 of 11

merging of multiple sheet, with forced repetition

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    merging of multiple sheet, with forced repetition

    pls see second post
    Attached Files Attached Files
    Last edited by maheshwow; 01-18-2012 at 10:46 AM. Reason: requirement simplified

  2. #2
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: consolidation of data ranges in multiple sheet, with different multiplication fac

    i found this code for consolidation which merges all sheet in workbook in a given range Column-A to Column-G.
    http://www.rondebruin.nl/copy2.htm

    Option Explicit
    
    Sub CopyDataWithoutHeaders()
        Dim sh As Worksheet
        Dim DestSh As Worksheet
        Dim Last As Long
        Dim shLast As Long
        Dim CopyRng As Range
        Dim StartRow As Long
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        'Delete the sheet "RDBMergeSheet" if it exist
        Application.DisplayAlerts = False
        On Error Resume Next
        ActiveWorkbook.Worksheets("RDBMergeSheet").Delete
        On Error GoTo 0
        Application.DisplayAlerts = True
    
        'Add a worksheet with the name "RDBMergeSheet"
        Set DestSh = ActiveWorkbook.Worksheets.Add
        DestSh.Name = "RDBMergeSheet"
    
        'Fill in the start row
        StartRow = 2
    
        'loop through all worksheets and copy the data to the DestSh
        For Each sh In ActiveWorkbook.Worksheets
    
            'Loop through all worksheets except the RDBMerge worksheet and the
            'Information worksheet, you can ad more sheets to the array if you want.
            If IsError(Application.Match(sh.Name, _
                                         Array(DestSh.Name, "Information"), 0)) Then
    
                'Find the last row with data on the DestSh and sh
                Last = LastRow(DestSh)
                shLast = LastRow(sh)
    
                'If sh is not empty and if the last row >= StartRow copy the CopyRng
                If shLast > 0 And shLast >= StartRow Then
    
                    'Set the range that you want to copy
                    Set CopyRng = sh.Range(sh.Rows(StartRow), sh.Rows(shLast))
    
                    'Test if there enough rows in the DestSh to copy all the data
                    If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
                        MsgBox "There are not enough rows in the Destsh"
                        GoTo ExitTheSub
                    End If
    
                    'This example copies values/formats, if you only want to copy the
                    'values or want to copy everything look below example 1 on this page
                    CopyRng.Copy
                    With DestSh.Cells(Last + 1, "A")
                        .PasteSpecial xlPasteValues
                        .PasteSpecial xlPasteFormats
                        Application.CutCopyMode = False
                    End With
    
                End If
    
            End If
        Next
    
    ExitTheSub:
    
        Application.GoTo DestSh.Cells(1)
    
        'AutoFit the column width in the DestSh sheet
        DestSh.Columns.AutoFit
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End Sub
    This is want i needed, however with the ability to consolidate sheets referred to in summary page. Summary page also gives each sheet name & no. of times it should repeat in consolidated output.

    (I've made requirement bit simpler than 1st post so that i can modify it according to my need. later)
    Please help to update the above code with this feature.
    Last edited by maheshwow; 01-13-2012 at 12:42 PM.

  3. #3
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: consolidation of data ranges in multiple sheet, with different multiplication fac

    I understood from above code that "For Each sh In ActiveWorkbook.Worksheets is the code which selects sheets to be merged.
    Please help me modify it to call only for sheets given by me in summary page Column-A, and repeats the sheet entry as many times as mentioned in Column-B of summary page.

  4. #4
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: merging of multiple sheet, with forced repetition

    pls help. pl let me know if vba doesnt support this type of merging.

  5. #5
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: merging of multiple sheet, with forced repetition

    y is noone helping me on this....did i ask for something too much?
    i'll be really thankfull for a reply to my query.

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: merging of multiple sheet, with forced repetition

    Please Review the file that you attached.
    1. Summary sheet doesnt include the number of times.
    2. The QTY number for item "ABC" in the cosolidated sheet doesnt reflect any logic.
    Please describe exactly how the cosolidated sheet is calculated.
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  7. #7
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: merging of multiple sheet, with forced repetition

    Thanks a thousand times for replying. Now i see why i was getting no reply..sry for the stupidity...

    Attached files has "Summary" sheet which says that Sheet-A should repeat 1 time, Sheet-B 2 times & Sheet-C 1 time.
    The consolidated page is the output page where you'll see the Sheets A,B & C copied as per above criteria.

    Sir, you are a life saver, i would rep and kill you if you can find me a solution.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: merging of multiple sheet, with forced repetition

    Here you Go

    Sub MergeSheets()
    Dim shtSUM As Worksheet
    Dim shtCON As Worksheet
    Dim shtITEM As Worksheet
    Dim i, r, n, s As Long
    
    'deleting all the contents in the Consolidation sheet
    Set shtCON = ThisWorkbook.Worksheets("Consolidation")
    shtCON.Rows("1:" & shtCON.Cells.SpecialCells(xlCellTypeLastCell).Row).EntireRow.Delete
    
    'Here starts the cosolidation
    Set shtSUM = ThisWorkbook.Worksheets("Summary")
    r = 1
    For i = 2 To shtSUM.Cells.SpecialCells(xlCellTypeLastCell).Row
        If shtSUM.Range("A" & i) = "" Then Exit Sub
        If shtSUM.Range("B" & i) > 0 Then
            Set shtITEM = ThisWorkbook.Worksheets(shtSUM.Range("A" & i).Value)
            For n = 1 To shtSUM.Range("B" & i).Value
                s = shtITEM.Cells.SpecialCells(xlCellTypeLastCell).Row
                 shtITEM.Range(1 & ":" & s).Copy Destination:=shtCON.Range(r & ":" & r + s)
                r = r + s
            Next
        End If
    
    Next
    End Sub

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: merging of multiple sheet, with forced repetition

    That's good,
    Will do it for you.

  10. #10
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: merging of multiple sheet, with forced repetition

    Dear Mr.Kelshaer ,
    I dont have words to thank you.. I really appreciate your help. I owe you big one!!
    This could take me to new level in my career..you wouldnt even believe, all with help of genius..Kelshaer!

    THANKYOU FOR YOU HELP.. & I MEAN IT.

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: merging of multiple sheet, with forced repetition

    You are welcome.
    Just remember to help any one if you can

    And mark this thread as SOLVED

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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