Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro help for subtotal at top of column

I'm an experienced Excel user but new to macros. I'd like to have a
macro that creates a subtotal at the top of a column of numbers rather
than at the bottom, where Excel normally wants to put it. I've given
it a shot with the following code, but am stumped. Any advice?

Dim MyRange As Range
Start_Row = ActiveCell.Row
Start_Col = ActiveCell.Column
Row_Counter = 0
End_Row = 0

For Row_Counter = (Start_Row + 1) To 65536
If Cells(Row_Counter, Start_Col) = "" Then
End_Row = Row_Counter
Exit For
End If
Next Row_Counter

Set MyRange = Range(Cells(Start_Row + 1, Start_Col), Cells(End_Row - 1,
Start_Col))
ActiveCell.Offset(0, 0).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,[MyRange])"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default macro help for subtotal at top of column

Instead of code have you considered using a pivot table? One of the
formatting options is to place the aggregations (subtotals in this case) at
the top of the listing.
--
HTH...

Jim Thomlinson


" wrote:

I'm an experienced Excel user but new to macros. I'd like to have a
macro that creates a subtotal at the top of a column of numbers rather
than at the bottom, where Excel normally wants to put it. I've given
it a shot with the following code, but am stumped. Any advice?

Dim MyRange As Range
Start_Row = ActiveCell.Row
Start_Col = ActiveCell.Column
Row_Counter = 0
End_Row = 0

For Row_Counter = (Start_Row + 1) To 65536
If Cells(Row_Counter, Start_Col) = "" Then
End_Row = Row_Counter
Exit For
End If
Next Row_Counter

Set MyRange = Range(Cells(Start_Row + 1, Start_Col), Cells(End_Row - 1,
Start_Col))
ActiveCell.Offset(0, 0).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,[MyRange])"


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 greyed out when in column jfaulks Excel Worksheet Functions 0 October 2nd 09 06:59 PM
sort macro, subtotal and add lines after subtotal David Excel Discussion (Misc queries) 1 August 29th 09 10:56 AM
column subtotal Mel Excel Worksheet Functions 0 August 6th 08 04:38 PM
macro excel subtotal in subtotal GBO Excel Discussion (Misc queries) 2 November 29th 07 02:15 PM
Ignore zero in column for subtotal michaelberrier Excel Discussion (Misc queries) 3 August 1st 07 02:56 PM


All times are GMT +1. The time now is 09:54 AM.

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"