Solved

Excel Summary VBA

Posted on 2014-12-07
5
353 Views
Last Modified: 2014-12-08
Hello,
can you please help,
I'm trying to get the Grand Total at the end of my sheet , (Find last Row + 1) and Highlight.

Grand Total = Sum of the Totals of each city .
please see attached..

I have about 1500 - 2000 Rows.

Any Help is appreciated.
Sample.xlsx
0
Comment
Question by:W.E.B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 150 total points
ID: 40486232
Hi,
pls try with subtotal

see example

Regards
Sample-V1.xlsx
0
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 150 total points
ID: 40486570
Assuming your data doesn't start out with the rows for summing each city, you can add subtotals as rgonzo has suggested and then use the following to update them:

Sub Add_Subtotal()
    Selection.CurrentRegion.Select
    Selection.Subtotal GroupBy:=11, Function:=xlSum, TotalList:=Array(5, 6, 7, 8 _
        , 9, 10), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
End Sub

Open in new window

Thanks
Rob H
0
 
LVL 16

Expert Comment

by:Jerry Paladino
ID: 40486581
In the OUTLINE Group under the DATA menu, select the Subtotals icon to add one or multiple subtotals to your Excel list of data.   The data must have a header row and must be an Excel list (cannot be formatted as an Excel table).   With the cursor located in the data range, go to the Outline Group located under the DATA menu and select Subtotals.  The dialog box shown below will display and allow you to select the columns to sum ( or count, avg, min, max, etc…) and the column to use for the "On Change" column (City in this case).

Once the Subtotals are displayed, to the left of the row numbers are expand and collapse buttons.  Pressing one of these will expand or collapse the list of data to show only the city rows, etc…   Adding or deleting rows (and new cities, etc…)  will automatically update the subtotals.

You can highlight the Subtotal and the Grand Total Rows and they will maintain the color highlight as data is added or deleted.

Another option for this type of reporting is to use a Pivot Table.   The attached file has samples of both the Subtotals and the pivot tables.

HTH,
JerrySubtotal IconSubtotal DialogSubtotal Expand / CollapseQ-28576016.xlsx
0
 
LVL 16

Assisted Solution

by:Jerry Paladino
Jerry Paladino earned 200 total points
ID: 40486838
I reread your question and if you want the VBA to find the last row in the worksheet you can try this code...
Sub LastRow_WS()
' Returns the last used row in the active worksheet
    Dim rLastCell As Range
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
                    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
    Debug.Print "The last used row in this Worksheet is: " & rLastCell.Row
End Sub

Open in new window

0
 

Author Closing Comment

by:W.E.B
ID: 40487549
thank you all.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

626 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