Toggle subtotals...

B

billy-boy

I'm trying to use the same macro to 'toggle' the sub-total function in
Excel. I can currently apply a subtotal to the selected data range,
but I also want to remove all subtotals (if any exist) by using the
same macro.

Is there any poperty that will determine whether subtotals exist on a
worksheet?

Thanks,
Bill.
 
B

BrianB

Try this. Uses fact that ordinary data rows' OutlineLevels become
greater than 1 when SubTotals applied.

'-------------------------------------------
Sub ApplySubtotals()
' Check a row known to be ordinary data
If ActiveSheet.Rows(2).OutlineLevel = 1 Then
ActiveSheet.Range("A1").Subtotal _
GroupBy:=1, Function:=xlSum, TotalList:=Array(2, 3, 4, 5), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Else
ActiveSheet.Range("A1").RemoveSubtotal
End If
End Sub
'----------------------------------------------

Regards
BrianB
===========================================
 

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

Similar Threads


Top