hiding all groups in a workbook

xcdave

Board Regular
Joined
Nov 11, 2004
Messages
61
I am using the following code to go through my workbook and collapse all the groups:

Sub HideRowsColumns()

Dim i As Integer

For i = 1 To Sheets.Count

Sheets(i).Outline.ShowLevels RowLevels:=1
Sheets(i).Outline.ShowLevels ColumnLevels:=1

Next i

End Sub

The problem is that if my workbook contains sheets that are graphs, the code doesn't work.

What can I add to the code so that it skips any sheets that are graphs?

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
Untested but try this.
Code:
Sub HideRowsColumns()

Dim ws As Worksheet

For Each ws In Worksheets
     ws.Outline.ShowLevels RowLevels:=1
     ws.Outline.ShowLevels ColumnLevels:=1
Next ws

End Sub
 

xcdave

Board Regular
Joined
Nov 11, 2004
Messages
61
That works, but it takes over a minute to run the macro. I turned screen updating off, and it still took over 1 min. Any other ideas?
 

Forum statistics

Threads
1,171,269
Messages
5,874,748
Members
433,070
Latest member
omartarek

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