grouping

mort1703

Active Member
Joined
Sep 13, 2008
Messages
266
in excel I can group rows or columns together in order to show totals only when closed and when opened it shows all the information which makes up that total, how do I write a macro to do the same?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
To Open First level of Grouping:
Code:
    ActiveSheet.Outline.ShowLevels RowLevels:=2
To close all Group levels:
Code:
    ActiveSheet.Outline.ShowLevels RowLevels:=1
 
Upvote 0

brian_schneider

New Member
Joined
Mar 5, 2009
Messages
1
Is there a way to write a macro to auto group based on changing information in a column? Similar to the subtotal function but without the sub totals? I have spreadsheets that will contain the same format of data, but there could be more of it, so writing a macro to highlight a certain rows, then selecting the group function wouldn't work.
 
Upvote 0

mort1703

Active Member
Joined
Sep 13, 2008
Messages
266
Rows("34:38").Select
Selection.Rows.Group

is it possible to change the numbers above to variables
ie.

startrow = 34
endrow = 38

Rows(startrow:endrow).select
selection.rows.group
 
Upvote 0

mort1703

Active Member
Joined
Sep 13, 2008
Messages
266
with trial and error I have worked out the code for the grouping however it didn't work as planned.

Worksheets(ASheet).Range("A1").Select
startrow = 16
ActiveCell.Offset(startrow, 0).Select
Selection.Rows.Group

this allows me to group 1 row, however I need to adjust the above to cater for multiple rows.

so I guess I need someway to select the range based on 2 variables
 
Last edited:
Upvote 0

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Do you want to Create Groupings or Open existing Grouped rows?

To Create a Grouping using variables you almost had the code:
Code:
Sub GroupingTest()
StartRow = 34
EndRow = 38
    Rows(StartRow & ":" & EndRow).Group
    ActiveSheet.Outline.SummaryRow = xlAbove
End Sub
Note there is no need to Select the row first, just assign the setting in the code.

I like the Outline sign Above the group instead of Below it. Remove the "xlAbove" line if you want the group sign below the grouping.
Once it is set, all Grouping for that sheet is set that way. Other worksheets will remain set to "Below" unless that sheet is also changed.
 
Upvote 0

Forum statistics

Threads
1,191,690
Messages
5,988,041
Members
440,125
Latest member
vincentchu2369

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top