Google Answers Logo
View Question
 
Q: Excel Formula/Macro ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Excel Formula/Macro
Category: Computers
Asked by: teamministry-ga
List Price: $35.00
Posted: 10 Jan 2005 09:15 PST
Expires: 09 Feb 2005 09:15 PST
Question ID: 455025
I have an Excel Spreadsheet that tracks disbursements.  Page 1 looks like this:

Category    Draw1 Draw2 Draw3
Foundation   10
Kitchen                  100  
Roof               20     20  
Flooring     20
Windows      100

I want to create a summary spreadsheet that check each Draw category
and if there are numbers, will produce Summary output like this:

Draw 1
Foundation   10
Flooring     20
Windows      100

Draw 2
Roof         20

Draw 3
Kitchen      100
Roof          20

I would like to do this without having blank lines between each detail
line on the summary page.
Answer  
Subject: Re: Excel Formula/Macro
Answered By: maniac-ga on 10 Jan 2005 18:10 PST
Rated:5 out of 5 stars
 
Hello Teamministry,

The macro (at the end of the answer) should do what you have asked
for. I tested it with the following data on the first sheet:

Category    Draw 1   Draw 2   Draw 3
Foundation      10
Kitchen                          100
Roof                     20       20
Flooring        20
Windows        100

And produced the following result on the second [previously empty] sheet.

Draw 1	
Foundation      10
Flooring        20
Windows        100
	
Draw 2	
Roof            20
	
Draw 3	
Kitchen        100
Roof            20

Other than slight formatting differences, this appears to be the
result you asked for.

The titles of each summary region was taken from the first row of each
column in the original data. The names for each data row was taken
from the first column of each row in the original data.

You should be able to add it to an existing data spreadsheet with the
following steps (the commands may vary slightly on your system - make
a clarification request if you have problems following these steps):

[1] Open the data spreadsheet

[2] Use the menu
  Tools -> Macro -> Visual Basic Editor
to start the Visual Basic Editor (VBE).

[3] In VBE, use the menu
  Insert Module
An empty window titled something like "teamministry.xls - Module 1
(code)" should appear.

[4] Copy / paste the macro (at the end of the answer) into this window.

[5] May any changes necessary. I have commented in a few places where
a change may be needed. For example, I assume the data is on the first
sheet and the summary goes on the second sheet. If this is not true,
change the lines
    CS = 1
    SS = 2
to the right sheet numbers.

[6] In VBE, use the menu
  Close and return to Microsoft Excel
to return to the excel spreadsheet.

[7] Make sure the summary sheet is empty.

[8] Select a cell in the data region of the data sheet. Ensure there
are no blank rows or columns in the data to be processed. Run the
macro using the menu
  Tools -> Macro -> Macros...
and select Summarize from the list and then Run.

The macro should run without any further interaction. When the "busy
cursor" goes away (an hourglass on my system), the macro is complete.

Note that the macro will be saved with the worksheet. Subsequent
attempts to open that worksheet should cause Excel to prompt you with
an "are you sure" type message which you should respond with "Enable
Macros". If the macro is disabled, when the spreadsheet is loaded, you
cannot run it.

If you have any problems using this macro or the instructions are
unclear to you, please make a clarification request.
  --Maniac

--- source code of Summarize macro follows ---

Sub Summarize()
'
' Summarize Macro
' Macro created on 1/10/2005 by Maniac
' Extract and summarize values in separate sheet
'
    Dim S As Object
    
'   Assume data on first sheet, and summary on second sheet
'   Revise here if change needed
    CS = 1
    SS = 2
    Set S = Selection.CurrentRegion
    sRows = S.Rows.Count - 1
    sCol = S.Columns.Count - 1
'
    R = 1  ' row of summary sheet active
    For I = 1 To sCol
        ' copy title for next summary region
        SV$ = S.Cells(1, I + 1).Value
        Sheets(SS).Select
        Cells(R, 1).Value = SV$
        R = R + 1
        Sheets(CS).Select
        For J = 1 To sRows
            V = S.Cells(J + 1, I + 1).Value
            If (V <> 0) Then
                C$ = S.Cells(J + 1, 1).Value
                Sheets(SS).Select
                Cells(R, 1).Value = C$
                Cells(R, 2).Value = V
                R = R + 1
                Sheets(CS).Select
            End If
        Next J
        R = R + 1
    Next I
End Sub
teamministry-ga rated this answer:5 out of 5 stars and gave an additional tip of: $25.00
Outstanding!!! Works like a champ.  Thank you very much.  This saves
me a lot of time and effort.  I appreciate your detailed instructions!

Comments  
Subject: Re: Excel Formula/Macro
From: stone07-ga on 10 Jan 2005 14:58 PST
 
You should replace all columns that are empty whith each draw with
zeros (0), select all rows in column that make a result, and put in a
desired colum, beside mentioned, as formulae (type in) "=SUM(A1:A5)",
if all of your draw1's are in column A, "=SUM(B1:B5)" if all your
draw2's are in column B, etc...  The resulting cells containing
"=SUM(...)" can be located anywhere you want in your spreadsheet.

You may want analytical results as well, saying if the value iz zero
or nothing - "give me a sum of those that are valued". In this case,
it would be probably easier if you rearange this setup to contain only
items of value or use some advanced analytical tool, such as Access
database.
Subject: Re: Excel Formula/Macro
From: teamministry-ga on 10 Jan 2005 16:59 PST
 
Thanks for your comments.  The spreadsheet is used for bidding and
tracking jobs and I have put a lot of time in it.  I have several
spreadsheets that are linked together and work very well for what I am
trying to do.  I am looking for a way to make a summary page that
contains the detail of each draw on it without having a lot of blank
rows.  I may not be able to do this with Excel but I'm hoping there is
a way without moving to access.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy