labels for subtotals

C

childofthe1980s

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
 
J

Jef Gorbach

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top