pls see second post
pls see second post
Last edited by maheshwow; 01-18-2012 at 10:46 AM. Reason: requirement simplified
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
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.![]()
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
(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.
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.
pls help. pl let me know if vba doesnt support this type of merging.
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.
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....
- Thank those who have helped you by clicking the Star below their post.
- 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
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.
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
That's good,
Will do it for you.
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.
You are welcome.
Just remember to help any one if you can
And mark this thread as SOLVED
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks