Problem with Macro for Expanding and Collapsing Rows

phenixwars

New Member
Joined
Feb 20, 2015
Messages
15
Hello I have created some buttons that have macros assigned to them to expand/collapse grouped rows on click.

There are two levels of grouped rows. One level, which has its own Expand All button, will expand/collapse all groups. The other level is just an Expand button which will expand/collapse the smaller groups within the large group. The macro works fine on the first sheet, making all the buttons disappear when I collapse all (expect for the Expand All button), but then on the other sheets when I apply the same macro the buttons for the smaller groups of rows all bundle and show underneath the Expand All button. This is a problem only because if these buttons were to be clicked they cause the file to expand random rows and throws the whole sheet into a mess where you can only collapse and expand some groups and not others.

I have used the original macro from sheet 1 and just renamed it for each different sheet. I suspect that this is my problem. I'm wondering if there is a proper macro that will do the same thing but will recognize the active sheet and apply itself to it without interfering with the other sheets.

Here is a link to download a sample of my workbook: https://onedrive.live.com/redir?resid=6D21E9845F393FE7!22850&authkey=!AOHJsFR5USpKJV8&ithint=file%2cxlsm Don't open this with Excel Online because for some reason it doesn't show the buttons.

Here are the macros I'm using:

Expand All Button Macro:

Public Trigger As Boolean

Sub LevelShow()

If Trigger = False Then
Sheets(1).Outline.ShowLevels RowLevels:=2
Trigger = True
Else
Sheets(1).Outline.ShowLevels RowLevels:=1
Trigger = False
End If

End Sub

******
Expand Button macro:

Sub ExpandorCloseGroup()

Dim CB As Shape
Set CB = ActiveSheet.Shapes(Application.Caller)
TlcRow = CB.TopLeftCell.Row

If Rows(TlcRow + 0).ShowDetail = True Then
Rows(TlcRow + 0).ShowDetail = False
Else
If Rows(TlcRow + 0).ShowDetail = False Then
Rows(TlcRow + 0).ShowDetail = True

End If
End If


End Sub
******

Thank you in advance for all your help!:biggrin:
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Ok just made a new workbook and applied the same formatting with the buttons and added the same macros as on the other worksheet and now I get the same problem even on the first sheet where the Expand buttons pile up under the Expand All buttons when they should disappear. As well as them not working properly. I guess its something with one of the macros but I honestly don't know how to edit them. I found these macros online and used them but I don't know VBA enough to edit much. Any help is appreciated. Thanks!
 
Upvote 0
Ok so I'm still fiddling with this.

These macros work on the first two workbooks I created only on the first sheet. The rest of the sheets neither macro works.
I created a third workbook and now the Expand All macro works fine with the exception that none of the buttons in the rows are hidden they just pile on top of each other and appear as one button.
The Expand or ExpandCloseGroup macro doesn't work at all its a total mess.

So I am just asking anyone if you could please help me to just type up a macro that will expand collapse groups on 3 levels. Level 1 and 2 to expand/collapse all grouped. Level 3 and 2 to expand/collapse the smaller groups within the large group. I will apply these macros to two different buttons (Expand All and Expand). Can anyone please provide a macro? I'm just learning VBA I honestly just edit code only when I understand it which is not always but with a good explanation I can get it. :confused:

Any help would be appreciated.
 
Upvote 0
Nevermind turns out it was such an easy solution in case anyone wants to know. The buttons properties they had to be set to move and resize with cell. Then I was easily able to use my above code with no problems. Please close this thread thanks.
 
Upvote 0

Forum statistics

Threads
1,216,551
Messages
6,131,310
Members
449,642
Latest member
jobon

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