Dear all,
I am trying to write two macros, attached to buttons, that allow all groups within the excel file to be collapsed or expanded (one button collapses, one expands).
I have a macro that successfully cycles through all the sheets in the workbook and changes the colour of A1 and I have a macro that collapses and expands the groups on one sheet. Unfortunately replacing the "colour A1" code with the "collapse groups" code results in an error with a select statement.
I've seen elsewhere "select" statements should be avoided but have minimal vba knowledge so don't know how to avoid or why they cause problems.
Code (that results in the error) is:
Sub Button4_Click()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
Next
End Sub
Any help greatly appreciated!
(just FYI, the buttons are on the second sheet of the book currently, there won't ever be groups on sheet 1).
Regards
Tim
I am trying to write two macros, attached to buttons, that allow all groups within the excel file to be collapsed or expanded (one button collapses, one expands).
I have a macro that successfully cycles through all the sheets in the workbook and changes the colour of A1 and I have a macro that collapses and expands the groups on one sheet. Unfortunately replacing the "colour A1" code with the "collapse groups" code results in an error with a select statement.
I've seen elsewhere "select" statements should be avoided but have minimal vba knowledge so don't know how to avoid or why they cause problems.
Code (that results in the error) is:
Sub Button4_Click()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
Next
End Sub
Any help greatly appreciated!
(just FYI, the buttons are on the second sheet of the book currently, there won't ever be groups on sheet 1).
Regards
Tim