Can you assign multiple click events to a button?

vbafun

New Member
Joined
Nov 23, 2014
Messages
9
Hello Excel Community,

I have a control sheet that runs a variety of macros in my workbook, but I'd like to reduce some of the formatting control buttons if possible. Basically, I have some procedures that only hide or un-hide rows/columns for presentation purposes, but I'd like my users to be able to use 1 button (i.e 1 click will hide, a second click will un-hide).

Is this possible or am I stuck with 2 buttons?

Cheers
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,

You could set a global variable to act as a switch and then call one routine or another based on that value, like so.

Code:
Global Button_Pushed As Boolean

Sub Button1_Click()
Button_Pushed = Not Button_Pushed

If Button_Pushed = True Then Call HideStuff
If Button_Pushed = False Then Call UnhideStuff

End Sub

Sub HideStuff()
'Your code here
End Sub

Sub UnhideStuff()
'Your other code here
End Sub
 
Upvote 0
It's possible. You'd just need to have one routine that hides the rows if they're visible and unhides them if they aren't.
 
Upvote 0
You can toggle the Hidden property like this:

Code:
Private Sub CommandButton1_Click()
    With Range("A1:A10").EntireRow
        .Hidden = Not .Hidden
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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