Formerly Best Training
© 2024 STL. All Rights Reserved.
All prices offered for business users and exclude VAT. E&OE
2nd Floor, CA House, 1 Northey Street, Limehouse Basin, London, E14 8BT. United Kingdom
Forum home » Delegate support and help forum » Microsoft Excel Training and help » Sorting Subtotals
Resolved · Low Priority · Version 2003
Nick has attended:
Excel VBA Intro Intermediate course
Is there a way of ensuring Subtotals stay group when using an a-z sort?
Hello Nick
Thank you for your question and welcome to the forum.
Are these subtotals you have added to the spreadsheet using Data - Subtotal or by another means?
Kind regards
Amanda
Hi Amanda,
The subtotals are added by a visual basic macro as below!
Many Thanks,
Nick
' Sort by name and subtotal
Columns("A:AF").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(6, 7, 8, 9, _
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, _
28, 29, 30, 31, 32), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Font.Bold = True
|
Excel tip:Multiple Lines of Text in a CellAs an alternative to the Text Wrapping facility, type a word or two, press Alt+Enter to get a new line, type more text, and continue the process for as many lines as you need. Enter as normal when you have finished. |
We'll call during UK business hours
Server loaded in 0.07 secs.