Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Grouping in Excel?

Status
Not open for further replies.

danomaniac

Programmer
Jan 16, 2002
266
US
Is there any way to expand or collapse a data group in Excel using VBA?

 
Yes there is - we have a report where we specify the group level for each line we report, then apply using this code (not mine, but a more clever colleague's ;-)):

Code:
'First set outline settings for Group method
With l_wksReport.Outline
  .SummaryRow = xlSummaryAbove
  .AutomaticStyles = True
End With
'Now switch the group on: l_sRefersTo = the rows to group, e.g. [b]"8:20"[/b]
l_wksReport.Rows(l_sRefersTo).Group
'Hide the details under the rows you've grouped;
'l_iGroupStart = the first row of the group - in the example row [b]8[/b]
l_wksReport.Rows(l_iGroupStart).ShowDetail = False

HTH

Cheers
Nikki
 
Thanks Nikki.

All I needed was Rows(x).ShowDetail = False

 
Hi,

This function appears to be just what I need to use for expanding and collapsing grouped rows in my Excel sheet via VBA. However, inexperienced as I am in using VBA in Excel, could anyone provide me with an example of how to actually use this function?

Best regards and thanks in advance,
B / Denmark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top