Expanding and collapsing grouped rows, using VBA

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
Hi all

I have a worksheet in which I have many groups set up.
This all works fine.
I would like to add a couple of buttons to give users the option to collapse all groups, and to expand all groups.
Can anyone help me with the code to do this please ?

I have done a search on this board, and found code that will CREATE the groups, but I don't need to do that.
I have also tried using the macro recorder while I collapse or expand a group, and no code seems to get recorded.
I'm using 2007.

Any ideas ?

Thanks in advance for any help !
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
don't know if you still need it

Code:
ActiveSheet.Outline.ShowLevels RowLevels:=1 ' to collapse the rows
ActiveSheet.Outline.ShowLevels RowLevels:=2 ' to expand the rows
 
Upvote 0
Hi all
:
I have also tried using the macro recorder while I collapse or expand a group, and no code seems to get recorded.
I'm using 2007.

Any ideas ?

Thanks in advance for any help !
I am also using Excel 2007. Funny thing I noticed is:

a. The macro recorder doesn't catch anything if you click on individual groups for showing / collapsing.

b. But if you click on the Level numbers then it records code like below:
Code:
    ActiveSheet.Outline.ShowLevels RowLevels:=2
    ActiveSheet.Outline.ShowLevels RowLevels:=1
as posted by hippiehacker!
 
Upvote 0

Forum statistics

Threads
1,221,557
Messages
6,160,477
Members
451,650
Latest member
kibria

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
Back
Top