Solved

Create Summary Page Shenanigans

Posted on 2011-03-19
10
242 Views
Last Modified: 2012-06-27
Hello all,

I have a worksheet called "AUT".  It is the fourth worksheet in the workbook.  I would like to copy the range (A26:R43) for all worksheets post the fourth worksheet, underneath each other, into the worksheet titled "AUT".  This will create a summary page that has all the ranges (A26 :R43) from all the other worksheets.

Any help would be greatly appreciated.

Many thanks, Alan.
0
Comment
Question by:Canders_12
  • 5
  • 4
10 Comments
 
LVL 14

Expert Comment

by:theras2000
ID: 35173284
Attach the workbook, or a demo if it's private.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35173312
Try this:  and see attached spreadsheet demo

The app GatherData goes through every worksheet, copying the range specified.  note, it clears the AUT tab of all data before starting.

Sub GatherData()
Dim mySheet As Worksheet
Dim myOutputCursor As Range
Dim rSize As Integer, cSize As Integer

    rSize = Range("A26:R43").Rows.Count
    cSize = Range("A26:R43").Columns.Count
    
    Sheets("AUT").Select
    Cells.Clear
    
    Set myOutputCursor = ActiveSheet.Range("A1")
    
    For Each mySheet In Application.Worksheets
        If mySheet.Name <> "AUT" Then
            
            myOutputCursor.Resize(rSize, cSize).Value = mySheet.Range("A26:R43").Value
            Set myOutputCursor = myOutputCursor.Offset(rSize, 0)
            
        End If
    Next mySheet

Open in new window

Cheers,

Dave
GatherDataAUT-r1.xlsm
0
 

Author Comment

by:Canders_12
ID: 35173369
Theras2000;

It is sensitive :/ will try to Mock up a quick demo.

Dave;

Almost ideal, is there an easy way to tweak code so it all gets the information for all worksheets that are after the AUT worksheet?

Many thanks.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35173410
Ok - please be clear.  You want to gather information for worksheets AFTER AUT - but that same range, right?

Dave
0
 

Author Comment

by:Canders_12
ID: 35173424
That is correct, apologies for my ambiguity. If it helps "AUT" will ALWAYS be the fourth worksheet.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Canders_12
ID: 35173425
That is correct, apologies for my ambiguity. If it helps "AUT" will ALWAYS be the fourth worksheet.
0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 35173431
Ok - this copies the same range, but for only those sheets that come AFTER the AUT sheet

see attached demo that its working.

Methodology - figure out the # worksheets, then loop through till "AUT" is found, from that point, copy the data.

Here's the code:

Sub GatherData()
Dim myOutputCursor As Range
Dim rSize As Integer, cSize As Integer
Dim countSheets As Integer, i As Integer, foundAUT As Boolean

    rSize = Range("A26:R43").Rows.Count
    cSize = Range("A26:R43").Columns.Count
    countSheets = ActiveWorkbook.Sheets.Count
    foundAUT = False
    
    Sheets("AUT").Select
    Cells.Clear

    
    For i = 1 To countSheets
        If foundAUT Then
            myOutputCursor.Resize(rSize, cSize).Value = ActiveWorkbook.Sheets(i).Range("A26:R43").Value
            Set myOutputCursor = myOutputCursor.Offset(rSize, 0)
        Else
            If ActiveWorkbook.Sheets(i).Name = "AUT" Then
                foundAUT = True
                Set myaut = ActiveWorkbook.Sheets(i)
                myaut.Activate
                Set myOutputCursor = myaut.Range("A1")
            End If
        End If
    Next i
    
End Sub

Open in new window

Enjoy!

Dave
GatherDataAUT-r2.xlsm
0
 

Author Closing Comment

by:Canders_12
ID: 35173437
Dave,

Excellent solution. Many many thanks for your swift replies.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35173443
This one's a bit more efficient - starting with the AUT sheet (versus finding it), then going to the sheets.count end...

code (and see attached file):

Sub GatherData()
Dim myOutputCursor As Range
Dim rSize As Integer, cSize As Integer
Dim countSheets As Integer, i As Integer

    rSize = Range("A26:R43").Rows.Count
    cSize = Range("A26:R43").Columns.Count
    countSheets = ActiveWorkbook.Sheets.Count
    
    Sheets("AUT").Cells.Clear
    
    Set myOutputCursor = Sheets("AUT").Range("A1")
    
    For i = Sheets("AUT").Index + 1 To countSheets
        myOutputCursor.Resize(rSize, cSize).Value = ActiveWorkbook.Sheets(i).Range("A26:R43").Value
        Set myOutputCursor = myOutputCursor.Offset(rSize, 0)
    Next i
    
End Sub

Open in new window

Dave
GatherDataAUT-r3.xlsm
0
 

Author Comment

by:Canders_12
ID: 35173450
Above and beyond the call of duty.... Thank you :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now