Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Subtotal \ Grand Total in VBA


I need to subtotal a range at each change in "CTR" with VBA code.
I acheived this with a macro recording but I can't figure out the next
part which is this.

I need to get the Grand total that appears at the bottom of the sum
range
To show up at the top of the worksheet in range ("P2").


I tried to make the cell equal xlSUM but that always gives -4175


Thanks
Charles


--
mrdata
------------------------------------------------------------------------
mrdata's Profile: http://www.excelforum.com/member.php...o&userid=17899
View this thread: http://www.excelforum.com/showthread...hreadid=543677

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Subtotal \ Grand Total in VBA

It sounds like you are using the built in subtotal method. Assume column P
contains the values you want to grandtotal.

After your code that builds the subtotal, try putting in lines of code like
this

set rng = Range("P3",cells(rows.count,"P").End(xlup))
Range("P2").formula = "=subtotal(9," & rng.Address & ")"

Adjust to fit your actual locations.

--
Regards,
Tom Ogilvy


"mrdata" wrote:


I need to subtotal a range at each change in "CTR" with VBA code.
I acheived this with a macro recording but I can't figure out the next
part which is this.

I need to get the Grand total that appears at the bottom of the sum
range
To show up at the top of the worksheet in range ("P2").


I tried to make the cell equal xlSUM but that always gives -4175


Thanks
Charles


--
mrdata
------------------------------------------------------------------------
mrdata's Profile: http://www.excelforum.com/member.php...o&userid=17899
View this thread: http://www.excelforum.com/showthread...hreadid=543677


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Subtotal \ Grand Total in VBA


Tom:
The code works great but it does not give me the result's I need.

First I only want to have a grand total in range P2
Currently I get the grand total below the data and in range P2

Also Is there a way to format the subtotal and grand total results to
show thousands. without having to do it manualy.

Here is the code I am using.


Range("A4").Select
Selection.Subtotal GroupBy:=11, Function:=xlSum, TotalList:=Array(9),
_
Replace:=True ', PageBreaks:=False ', SummaryBelowdata:=True

Set rng = Range("I5", Cells(Rows.Count, "I").End(xlUp))
Range("P2").Formula = "=subtotal(9," & rng.Address & ")"

I have the Summarybelowdata part remed out but it still gives a Grand
total
Below data.


Thanks
Charles


--
mrdata
------------------------------------------------------------------------
mrdata's Profile: http://www.excelforum.com/member.php...o&userid=17899
View this thread: http://www.excelforum.com/showthread...hreadid=543677

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtotal "grand total" populates at top of data smartgal Excel Discussion (Misc queries) 4 September 26th 08 04:23 PM
Duplicate Running Total Grand Total In Pivot Table Mathew P Bennett[_2_] Excel Discussion (Misc queries) 1 August 17th 08 03:13 AM
Subtotal and Grand Total Functions [email protected] Excel Discussion (Misc queries) 2 July 4th 08 12:53 PM
Excel 2002 : Any single button to get sub total and grand total ? Mr. Low Excel Discussion (Misc queries) 2 May 22nd 07 08:46 AM
Subtotal of Subtotal displays Grand Total in wrong row Thomas Born Excel Worksheet Functions 5 January 6th 05 01:46 PM


All times are GMT +1. The time now is 09:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"