Macro Button that deactivates/activates worksheet change events

coach_veto

New Member
Joined
Jan 26, 2016
Messages
15
Hi guys,

I have a worksheet with a long list of worksheet change events.

I am trying to create a toggle, preferably a button on the worksheet, that will deactivate all the change event code when clicked, but then activate the same code if clicked again and so on...

The purpose is so users of this template I'm working on are able to use the worksheet without the change events working if they don't want them to. Kind of like flipping a switch.

Any ideas regarding the type of code required or how to go about this?

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You could do it with one button or even a toggle button.

Add a Forms button to the worksheet, give it a caption like 'Deactivate Events', right click it, select Assign Macro... and click New.

You should now see something like this.
Code:
Sub Button1_Click()
    
End Sub
This is where the code goes, and here's the code.
Code:
Sub Button1_Click()
Dim btn As Object

    Set btn = Sheets("Sheet1").Shapes(Application.Caller)
    
    If btn.OLEFormat.Object.Caption = "Deactivate Events" Then
        Application.EnableEvents = False
        btn.OLEFormat.Object.Caption = "Activate Events"
    Else
        Application.EnableEvents = True
        btn.OLEFormat.Object.Caption = "Deactivate Events"
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,019
Messages
6,128,311
Members
449,439
Latest member
laurenwydo

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