Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MAKE SUBTOTAL APPLICATION ON AND OFF IN MACRO

Hi I want to get subtotals in the range (B1:K200) by every value
change in col B. Is there way that I can have some sort of macro on a
Toggle Button that when I press button then it should put subtotals in
the range but when I press it again then it should remove the
subtotals.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default MAKE SUBTOTAL APPLICATION ON AND OFF IN MACRO

On Apr 19, 1:38*am, K wrote:
Hi I want to get subtotals in the range (B1:K200) by every value
change in col B. *Is there way that I can have some sort of macro on a
Toggle Button that when I press button then it should put subtotals in
the range but when I press it again then it should remove the
subtotals.


Hi K

You can use the following code:

Sub Add_SubTotals()
Dim r As Range

Set r = Range("$A$1:$K$200")

r.Sort Key1:=Range("B2"), Order1:=xlAscending, _
Header:=xlYes

r.Subtotal GroupBy:=2, Function:=xlSum, _
TotalList:=Array(7), Replace:=True, _
PageBreaks:=False, SummaryBelowData:=True


End Sub

Sub Remove_SubTotals()
Dim r As Range
Set r = Range("$A$1:$K$200")
r.RemoveSubtotal
End Sub

Please note that change this code to your environment like change the
Array(7) to whatever column number your total has to appear in. If
totals in multiple columns are required, you can write Array(7,9) etc.
Also please add a button to your worksheet by going to View/Toolbars
and opening the Forms toolbar, add a button and assign macros to those
buttons.

Hope that helps.

Thanks
Anant
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default MAKE SUBTOTAL APPLICATION ON AND OFF IN MACRO

On 19 Apr, 02:10, wrote:
On Apr 19, 1:38*am, K wrote:

Hi I want to get subtotals in the range (B1:K200) by every value
change in col B. *Is there way that I can have some sort of macro on a
Toggle Button that when I press button then it should put subtotals in
the range but when I press it again then it should remove the
subtotals.


Hi K

You can use the following code:

Sub Add_SubTotals()
* * Dim r As Range

* * Set r = Range("$A$1:$K$200")

* * r.Sort Key1:=Range("B2"), Order1:=xlAscending, _
* * * * * * * * *Header:=xlYes

* * r.Subtotal GroupBy:=2, Function:=xlSum, _
* * * * * * * *TotalList:=Array(7), Replace:=True, _
* * * * * * * *PageBreaks:=False, SummaryBelowData:=True

End Sub

Sub Remove_SubTotals()
* * Dim r As Range
* * Set r = Range("$A$1:$K$200")
* * r.RemoveSubtotal
End Sub

Please note that change this code to your environment like change the
Array(7) to whatever column number your total has to appear in. If
totals in multiple columns are required, you can write Array(7,9) etc.
Also please add a button to your worksheet by going to View/Toolbars
and opening the Forms toolbar, add a button and assign macros to those
buttons.

Hope that helps.

Thanks
Anant


Thanks Anant.
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
How do I make AutoSum really Sum, not Subtotal Pearl Excel Worksheet Functions 7 April 3rd 23 06:43 PM
sort macro, subtotal and add lines after subtotal David Excel Discussion (Misc queries) 1 August 29th 09 10:56 AM
Execute a Macro from one excel Application to another Application Jason Zischke Excel Programming 2 January 30th 08 11:45 AM
macro excel subtotal in subtotal GBO Excel Discussion (Misc queries) 2 November 29th 07 02:15 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM


All times are GMT +1. The time now is 06:44 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"