Collapsing Groups across Multiple Worksheets

Gronk_h8er

Board Regular
Joined
Jan 6, 2009
Messages
63
Hi all,

I need help in putting together a macro that collapses groups across all of my worksheets.

I know the VBA to collapse the groups in the active worksheet

Code

ActiveSheet.Outline.ShowLevels RowLevels:=1

/Code

But i don't know how to write a macro that will go to each worksheet in my workbook and collapse the groups.

Assume the worksheets are called 'sheet1', 'sheet2' etc.

Any help would be greatly appreciated!

Regards,

Thomas
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I imagine this would work:
Code:
Dim ws as Worksheet

ON Error Resume Next
For each ws in ActiveWorkbook.Worksheets
    .Outline.ShowLevels RowLevels:=1
Next ws

We wrap it in an error handler so if there's no outine, no probs - though this might not matter anyway (not sure what would happen).
 
Upvote 0
Hi Xenou,

It appears to have a problem with

.Outline.ShowLevels RowLevels:=1

It says it is an invalid or unqualified reference.

I unfortunately have no idea what this is or how to fix it!

Thanks,

Thomas
 
Upvote 0
oops...my bad.

Should be:
Code:
Dim ws as Worksheet

On Error Resume Next
For each ws in ActiveWorkbook.Worksheets
    [COLOR="Red"][B]ws[/B][/COLOR].Outline.ShowLevels RowLevels:=1
Next ws
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,142
Members
448,551
Latest member
Sienna de Souza

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