Stumped on my Summary Sheet

jthomas3029

New Member
Joined
Jun 29, 2020
Messages
30
Office Version
  1. 2010
Platform
  1. Windows
I copied a Mr. Excel VBA formula, Copy Wrksheet range in VBA consolidation. It has worked well until I added more data into the rows on my worksheets. The individual worksheets are displaying the correct calculations but the summary sheet does not. The summary sheet draws upon a formula from a previous row within the summary sheet even though it reflects the correct worksheet formula. To add to it the first worksheet is always correct on the summary sheet no matter how many new rows of data I add.
 

Attachments

  • Excel consolidation worksheet.jpg
    Excel consolidation worksheet.jpg
    88.7 KB · Views: 16

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the board, try changing
VBA Code:
Set rngCopy = wrkSheet.Range("A2:U30")
to
VBA Code:
Set rngCopy = wrkSheet.Range("A2:U" & wrkSheet.Range("A" & Rows.Count).End(xlUp).Row)

In future please can you post VBA code directly in the thread (wrapped in code tags) as we can't copy and paste from an image.
 
Upvote 0
Welcome to the board, try changing
VBA Code:
Set rngCopy = wrkSheet.Range("A2:U30")
to
VBA Code:
Set rngCopy = wrkSheet.Range("A2:U" & wrkSheet.Range("A" & Rows.Count).End(xlUp).Row)

In future please can you post VBA code directly in the thread (wrapped in code tags) as we can't copy and paste from an image.

Thank you for the timely suggestion; however, the issue is still present even with the modification.
 

Attachments

  • Laura's worksheet.jpg
    Laura's worksheet.jpg
    53.7 KB · Views: 5
  • Laura on summary sheet.jpg
    Laura on summary sheet.jpg
    53.2 KB · Views: 6
  • Xl2BB.jpg
    Xl2BB.jpg
    9.9 KB · Views: 6
Upvote 0
First of all with your XL2BB image you need to unzip the file.
Second what do you have in column A of each sheet i.e. do you have data and does the data go down to the last row in each sheet.
 
Upvote 0
Code:
Private Sub Worksheet_Activate()

    'Consolidates data from the range A2:N35 for every tab except the one it's part of.

    Dim wrkSheet As Worksheet
    Dim rngCopy As Range
    Dim lngPasteRow As Long
    Dim strConsTab As String
    
    strConsTab = ActiveSheet.Name 'Consolidation sheet tab name based on active tab.
        
    If Sheets(strConsTab).Cells(Rows.Count, "A").End(xlUp).Row >= 2 Then
        If MsgBox("Do you want to clear the existing consolidated data in """ & strConsTab & """", vbQuestion + vbYesNo, "Data Consolidation Editor") = vbYes Then
            Sheets(strConsTab).Range("A2:S" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents
        End If
    End If
        
    Application.ScreenUpdating = False
            
    For Each wrkSheet In ActiveWorkbook.Worksheets
    
    If wrkSheet.Name <> strConsTab And _
            wrkSheet.Name <> "Tables" Then
        
                
            Set rngCopy = wrkSheet.Range("A2:U" & wrkSheet.Range("A" & Rows.Count).End(xlUp).Row)
            lngPasteRow = Sheets(strConsTab).Cells(Rows.Count, "A").End(xlUp).Row + 1
            rngCopy.Copy Sheets(strConsTab).Range("A" & lngPasteRow)
            Application.CutCopyMode = False
            
        End If
    
    Next wrkSheet
    
    Application.ScreenUpdating = True
    
    MsgBox "The workbook data has now been consolidated.", vbInformation, "Data Consolidation Editor"

End Sub
 
Upvote 0
Every worksheet has a column A with the data beginning on A7 and ending on P7. Each worksheet does contain formulated rows without data in preparation of the data being entered.
 
Upvote 0
Each worksheet does contain formulated rows without data in preparation of the data being entered
That does make a difference but in the opposite way (i.e. it should be copying more rows than needed).
To adjust for that try the code below and then we will see where we are.

VBA Code:
Private Sub Worksheet_Activate()

    'Consolidates data from the range A2:N35 for every tab except the one it's part of.

    Dim wrkSheet As Worksheet
    Dim rngCopy As Range
    Dim lngPasteRow As Long
    Dim strConsTab As String
    
    strConsTab = ActiveSheet.Name                'Consolidation sheet tab name based on active tab.
        
    If Sheets(strConsTab).Cells(Rows.Count, "A").End(xlUp).Row >= 2 Then
        If MsgBox("Do you want to clear the existing consolidated data in """ & strConsTab & """", vbQuestion + vbYesNo, "Data Consolidation Editor") = vbYes Then
            Sheets(strConsTab).Range("A2:S" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents
        End If
    End If
        
    Application.ScreenUpdating = False
            
    For Each wrkSheet In ActiveWorkbook.Worksheets
    
        If wrkSheet.Name <> strConsTab And _
           wrkSheet.Name <> "Tables" Then
        
                
            Set rngCopy = wrkSheet.Range("A2:U" & wrkSheet.Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row)
            lngPasteRow = Sheets(strConsTab).Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row + 1
            rngCopy.Copy Sheets(strConsTab).Range("A" & lngPasteRow)
            
        End If
    
    Next wrkSheet
    
    Application.ScreenUpdating = True
    
    MsgBox "The workbook data has now been consolidated.", vbInformation, "Data Consolidation Editor"

End Sub
 
Upvote 0
Thank you.
VBA Code:
Private Sub Worksheet_Activate()

    'Consolidates data from the range A2:N35 for every tab except the one it's part of.

    Dim wrkSheet As Worksheet
    Dim rngCopy As Range
    Dim lngPasteRow As Long
    Dim strConsTab As String
    
    strConsTab = ActiveSheet.Name                'Consolidation sheet tab name based on active tab.
        
    If Sheets(strConsTab).Cells(Rows.Count, "A").End(xlUp).Row >= 2 Then
        If MsgBox("Do you want to clear the existing consolidated data in """ & strConsTab & """", vbQuestion + vbYesNo, "Data Consolidation Editor") = vbYes Then
            Sheets(strConsTab).Range("A2:S" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents
        End If
    End If
        
    Application.ScreenUpdating = False
            
    For Each wrkSheet In ActiveWorkbook.Worksheets
    
        If wrkSheet.Name <> strConsTab And _
           wrkSheet.Name <> "Tables" Then
        
                
            Set rngCopy = wrkSheet.Range("A2:U" & wrkSheet.Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row)
            lngPasteRow = Sheets(strConsTab).Columns(1).Find("*", , xlValues, , xlByRows, xlPrevious).Row + 1
            rngCopy.Copy Sheets(strConsTab).Range("A" & lngPasteRow)
            
        End If
    
    Next wrkSheet
    
    Application.ScreenUpdating = True
    
    MsgBox "The workbook data has now been consolidated.", vbInformation, "Data Consolidation Editor"

End Sub
I appreciate your work on my behalf. We are not quite there yet.
 

Attachments

  • VBA error msg.jpg
    VBA error msg.jpg
    18.2 KB · Views: 3
  • VBA Debug.jpg
    VBA Debug.jpg
    33 KB · Views: 3
Upvote 0
What is confusing to me that it works as designed on the first worksheet and the first few rows of next worksheets. I just switched the order of the worksheets and voila the first one is correct. I need to replicate the success with the first worksheet to the others. js...
 
Upvote 0
Are you 100% sure that every sheet has data in Column A?
 
Upvote 0

Forum statistics

Threads
1,216,750
Messages
6,132,498
Members
449,730
Latest member
SeanHT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top