0
votes

I have grouped few rows in my excel sheet. I have added couple of buttons to hide and unhide the rows. But I want to combine the code and have only one button which works more like a toggle button. I am not able to achieve this. These are my individual functions.

Sub Button1_Click()
    ActiveSheet.Outline.ShowLevels Rowlevels:=1
End Sub
Sub Button2_Click()
    ActiveSheet.Outline.ShowLevels Rowlevels:=2
End Sub

Any help with this is appreciated. Please note: I do not have any experience with VBA and I need this to be done for my maanger's requirement on one of his work.

Thanks

1
how do you wish your toggle button to work? When pressed it shows Rowlevels:1 and hides the other and vise versa?L42

1 Answers

0
votes

Try this:

Activesheet.rows(x & ":" & y).hidden=Not activesheet.rows(x & ":" & y).hidden

Where x to y are number of rows you want to hide. For instance:

Sub Button1_Click()
    ActiveSheet.Rows("2:4").Hidden = Not ActiveSheet.Rows("2:4").Hidden
End Sub