View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Udo Udo is offline
external usenet poster
 
Posts: 48
Default VBA: Auto Grouping

Hi Choo, Sally,

First of all, you need VBA to select what you want to get grouped.
Let's assume, that you are in the leftmost top cell of the range you
are interested in (in your example it would be A1). Then you run the
following code:
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

After that you can do the grouping. This code does it for you:
Selection.Subtotal GroupBy:=2, Function:=xlCount, TotalList:=Array(3),
_
Replace:=True, PageBreaks:=False, SummaryBelowData:=True

ActiveSheet.Outline.ShowLevels RowLevels:=2
The 2 means column 2 in your range contains which element should be
counted, the Array(3) says that the result of each counting should be
displayed in column 3 of your range. The last row says that it should
do the grouping and only display the results and hide the elements.

Hope this is what you have expected.
Have a nice weekend
Udo