Toggle Marco . . .

F

Fable

Greetings,

Im trying to get a macro button to "toggle" to cycle through th
different grouped views I created but I keep getting a compiling error
VBA is not my forte as maybe you can see and thoughts what Im doin
wrong?


Sub Toggle_View()
'
Sheets("Sheet1").Select
With ActiveSheet
If ActiveSheet.Outline.ShowLevels RowLevels:=1 = True then
ActiveSheet.Outline.ShowLevels RowLevels:=2 False
ActiveSheet.Outline.ShowLevels RowLevels:=3 False
Else
ActiveSheet.Outline.ShowLevels RowLevels:=2 True
ActiveSheet.Outline.ShowLevels RowLevels:=1 False
ActiveSheet.Outline.ShowLevels RowLevels:=3 False
Else
ActiveSheet.Outline.ShowLevels RowLevels:=3 True
ActiveSheet.Outline.ShowLevels RowLevels:=1 False
ActiveSheet.Outline.ShowLevels RowLevels:=2 False
End If
End With
End Sub

Thanking you in advance
 
D

Dave Peterson

This worked ok for me.

Option Explicit
Sub Toggle_View2()

Dim myRange As Range
Dim myCell As Range
Dim maxOutlineLevel As Long
Dim maxVisLevel As Long

With ActiveSheet
Set myRange = Intersect(.Columns(1), .UsedRange)
maxOutlineLevel = 0
maxVisLevel = 0
For Each myCell In myRange.Cells
If myCell.EntireRow.Hidden = False Then
If myCell.EntireRow.OutlineLevel > maxVisLevel Then
maxVisLevel = myCell.EntireRow.OutlineLevel
End If
End If
If myCell.EntireRow.OutlineLevel > maxOutlineLevel Then
maxOutlineLevel = myCell.EntireRow.OutlineLevel
End If
Next myCell

If maxVisLevel = maxOutlineLevel Then
maxVisLevel = 0
End If
maxVisLevel = maxVisLevel + 1

.Outline.ShowLevels RowLevels:=maxVisLevel
End With

End Sub
 
Top