Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
subtotal greyed out when in column | Excel Worksheet Functions | |||
sort macro, subtotal and add lines after subtotal | Excel Discussion (Misc queries) | |||
column subtotal | Excel Worksheet Functions | |||
macro excel subtotal in subtotal | Excel Discussion (Misc queries) | |||
Ignore zero in column for subtotal | Excel Discussion (Misc queries) |