ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   labels for subtotals (https://www.excelbanter.com/excel-programming/439793-labels-subtotals.html)

childofthe1980s

labels for subtotals
 
Hello:

I'm going to create an Excel macro that, among other things, subtotals a
column of numbers based on column B. Column B contains account numbers.
(So, the macro will sort by column B, first.)

I'd like for the row that shows the subtotal to have a distinct label. The
label essentially will come from column C. Column C contains the account
number description.

This subtotal label will make it easier for the end user to understand what
is being subtotaled.

Is it possible to program a subtotal "label" in Excel?

childofthe1980s

Jef Gorbach[_2_]

labels for subtotals
 
On Feb 21, 1:01*pm, childofthe1980s
wrote:
Hello:

I'm going to create an Excel macro that, among other things, subtotals a
column of numbers based on column B. *Column B contains account numbers.. *
(So, the macro will sort by column B, first.)

I'd like for the row that shows the subtotal to have a distinct label. *The
label essentially will come from column C. *Column C contains the account
number description.

This subtotal label will make it easier for the end user to understand what
is being subtotaled.

Is it possible to program a subtotal "label" in Excel?

childofthe1980s


The subtotal command automatically used the values in the selected
column, so perhaps this will do your desire? Obviously need to adjust
the range for your data.
It sorts the range by column(B) ascending, then subtotals the range
using a Sum function on column(C). Finally it auto-adjusts column(B)'s
width to accommodate the subtotal titles.

Sub test()
With Range("B3:C16")
.Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal
.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
End With
Columns("B:B").EntireColumn.AutoFit
End Sub


All times are GMT +1. The time now is 07:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com