We have a trivial problem regarding how to run a simple macro button. The purpose of this button is two-fold: expanding a row and collapsing a row.
1 on pressing the button this VBA command is initiated:
Sub Macro7()
Rows(7).ShowDetail = True
End Sub
This command expands row 7.
2 on pressing the button again (whilst the row is expanded), this VBA is initiated:
Sub Macro7()
Rows(7).ShowDetail = False
End Sub
This collapses the row.
Is there a way to link a button to two macros?
Thanks in advance!!!
M
Answers. You can add as many lines as you need. Execute the RunAll macro to run all macros mentioned in it. Yes, the subs should be below each other.
Right-click the item, click Expand/Collapse, and then do one of the following: To see the details for the current item, click Expand. To hide the details for the current item, click Collapse. To hide the details for all items in a field, click Collapse Entire Field.
You can also collapse rows using the Hide Detail command. To do this select the group of rows that you want to collapse. Now, go to the Data tab in the ribbon and click on Hide Detail. That will eventually collapse rows. To expand rows in excel, We can also apply two methods.
I'd like to be able to run a macro which would collapse or expand all grouped rows and columns for all selected worksheets. Click to expand... selected worksheets that Domenic provided you in your recent post. The result for Expand_All would look like this. You can adapt the other variations the same way. Thank you!! This is so helpful.
However, there are no dedicated buttons on the pivot table to expand/collapse the entire field. In Excel 2016 a new feature was added to pivot charts that allows us to expand or collapse the fields in the Rows area. You will see little plus and minus button in the bottom right corner of your pivot chart.
Keyboard shortcuts to Expand/Collapse fields: Expand Entire Field: Alt, A, J Or Menu Key, E, E Collapse Entire Field: Alt, A, H Or Menu Key, E, C Note: A cell in the Rows or Columns area must be selected for the keyboard shortcuts to work.
Sub Macro7()
With Rows(7)
.ShowDetail = Not .ShowDetail
End With
End Sub
No need to. Just adjust your macro to check the current state of your row (collapsed or expanded) and act accordingly:
Sub ExpandOrCollapse()
Rows(7).ShowDetail=IIF(Rows(7).ShowDetail,False,true)
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With