Please find the attached worksheet (named “Revised.Workbook.11.28.1.C.xlsm”) that I’m having issues getting the Master Sheet (Sheet 1) to populate with the data from each of the following 5 tabs (Tabs 2-6). A member of this forum named Roger Govier helped me several months ago in creating a Macro to populate the Master Sheet with the data contained within Worksheets 2-6, but I've been required to make changes to the format of the workbook and that apparently has thrown off the Macro. I've spent nearly the entire day trying to get this fixed and I just don't have the knowledge required to get it done at this time. I believe the problem may stem from the fact that Rows 1-3 make up my header row in my current workbook, whereas the previous version only used Row 1 for the header. Basically I am wondering if someone can please help me so that when the "Button" that Roger made on the Master Sheet (see top of Master Sheet) is pushed, the data will populate into the Master Sheet from Sheets 2-6. Here is a link to my original worksheet and here is the "formula" Roger provided me at that time to make the workbook populate the Master Sheet:
Sub CopySheets()
Dim i As Long, tbl As Range
Application.ScreenUpdating = False
Set tbl = Sheets(1).Cells(1).CurrentRegion
On Error Resume Next
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).ClearContents
For i = 2 To 6
Set tbl = Sheets(i).Cells(1).CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Copy Sheets(1).Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
Next
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Thanks in advance for any assistance someone can offer.
Brian
Hi Brian,
Firstly, please make sure you wrap all code in the appropriate tags (as I have done).
Secondly, I dare say the use of merged cells is causing part of the issue (merged cells and VBA do not mix). That said, try this while on the desired consolidation tab:
Regards,Option Explicit Sub ConsolidateSheets() Dim strConsCols As String, _ strConsTabName As String, _ strConsCol As String Dim wrtTab As Worksheet Dim lngRowLast As Long, _ lngRowStart As Long Dim xlCalc As XlCalculation Dim intPasteCount As Integer strConsCols = "A:Z" 'Column(s) to be consolidated, i.e. "A:A" or "A:Z". Change to suit. strConsCol = "A" 'Column to consolidate data to. Change to suit. lngRowStart = 4 'First data row number i.e. don't include header rows. Change to suit. If MsgBox("Is this """ & ActiveSheet.Name & """ the correct tab for the data to be consolidated to?", vbYesNo + vbQuestion, "Consolidate Sheet Tab Editor") = vbNo Then MsgBox "Run the macro from the desired consolidation tab.", vbInformation, "Consolidate Sheet Tab Editor" Exit Sub Else strConsTabName = ActiveSheet.Name With Sheets(strConsTabName) If WorksheetFunction.CountA(.Cells) > 0 Then lngRowLast = .Range(strConsCols).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row If lngRowLast >= lngRowStart Then .Rows(lngRowStart & ":" & lngRowLast).EntireRow.Delete End If End If End With End If With Application xlCalc = .Calculation .Calculation = xlCalculationManual .ScreenUpdating = False .StatusBar = "Please wait while the tabs are consolidated..." End With For Each wrtTab In ThisWorkbook.Sheets If wrtTab.Name <> strConsTabName Then If WorksheetFunction.CountA(Sheets(wrtTab.Name).Cells) > 0 Then lngRowLast = wrtTab.Range(strConsCols).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row If lngRowLast >= lngRowStart Then 'First paste needs to be set statically in case there's merged cells. If intPasteCount = 0 Then wrtTab.Range(Left(strConsCols, InStr(strConsCols, ":") - 1) & lngRowStart & ":" & Right(strConsCols, InStr(strConsCols, ":") - 1) & lngRowLast).Copy _ Sheets(strConsTabName).Range(strConsCol & lngRowStart) Else wrtTab.Range(Left(strConsCols, InStr(strConsCols, ":") - 1) & lngRowStart & ":" & Right(strConsCols, InStr(strConsCols, ":") - 1) & lngRowLast).Copy _ Sheets(strConsTabName).Cells(Cells(Rows.Count, strConsCol).End(xlUp).Row + 1, strConsCol) End If intPasteCount = intPasteCount + 1 End If End If End If Next wrtTab With Application .Calculation = xlCalc .StatusBar = "" .ScreenUpdating = True End With MsgBox "The data in columns " & strConsCols & " for each sheet tab have now been consolidated into the """ & strConsTabName & """ tab.", vbInformation, "Consolidate Sheet Tab Editor" End Sub
Robert
Last edited by Trebor76; 11-29-2011 at 11:10 PM.
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of my post
Thanks so much for providing the code for my workbook. The Master Sheet is populating when I run the Macro, but it is picking up the data from the Sheet labeled "DV" (Sheet 7) and my goal is for the Master Sheet to not include the "DV" sheet and only Sheets 2-6 at this time. The "DV" sheet is my sheet data validation and I didn't clarify that when I posted this on the forum. How can I avoid the Master Sheet picking up the data from DV while still populating Sheets 2-6? Again, thanks for your help with this workbook, I really appreciate it.
Hi Brian,
There are two ways to exclude the tab from being consolidated. One is by excluding the tab based on its name, which will work as long as the name of the tab doesn't change. To do this, change this line of code...
...to this:If wrtTab.Name <> strConsTabName Then
The other method is to exclude the index number (as Roger Govier's clever code does) of the relevant tab, which will still work if the tab is renamed but not if it's position in the workbook is changed. To use this method, change this line of code...If wrtTab.Name <> strConsTabName And _ wrtTab.Name <> "DV" Then
...to this:If wrtTab.Name <> strConsTabName Then
I've leave the decision as to which one to use to you.If wrtTab.Name <> strConsTabName And _ wrtTab.Index <> 7 Then
Regards,
Robert
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of my post
Can someone please explain to me how to create a legend on the Master Sheet of the sheet within the OP, as we are trying to create a legend but everytime the Master Sheet populates it takes the legend we created on each of the tabs that the Master Sheet pulls data from... I know there has to be a way to create a legend but I cannot for the life of me figure it out. Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks