Solved

Create Summary Page Shenanigans

Posted on 2011-03-19
10
240 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

757 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

20 Experts available now in Live!

Get 1:1 Help Now