Toggle Button change status (true/false), run macro

Mongy

Board Regular
Joined
Dec 9, 2002
Messages
64
Office Version
  1. 365
Platform
  1. Windows
Greetings,
I have added a toggle buttons which hide row arrays.
Also have VBA button.values for change of colours/text.

Looking for how to set the VBA for when button X is clicked to true, runs a macro, and when click to false runs a different macro.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Since you gave very few details try this:
So if toggle button is True do this if Toggle Button is false do this

VBA Code:
Private Sub ToggleButton1_Click()
'Modified  8/7/2022  9:27:40 PM  EDT

If ActiveSheet.ToggleButton1.Value = True Then
Range("A1").Interior.Color = vbRed
Else
Range("A1").Interior.Color = vbGreen
End If
End Sub
 
Upvote 0
My apologies.
This is the basic of what I'm trying to do. When the button is clicked to true, want to run the EstimateWatermark macro (it's a formatted named shape). When clicked to false, run the DeleteEstimateWatermark to delete the shape.
VBA Code:
Private Sub EstimateWatermarkButton_Click()
    If EstimateWatermarkButton.Value = True Then EstimateWatermarkButton.BackColor = vbGreen
    If EstimateWatermarkButton.Value = True Then EstimateWatermarkButton.Caption = "Estimate Watermark on"
    If EstimateWatermarkButton.Value = True Then EstimateWatermarkButton.ForeColor = vbBlack
    If EstimateWatermarkButton.Value = True Then Call EstimateWatermark
    
    If EstimateWatermarkButton.Value = False Then EstimateWatermarkButton.BackColor = vbRed
    If EstimateWatermarkButton.Value = False Then EstimateWatermarkButton.Caption = "Estimate Watermark off"
    If EstimateWatermarkButton.Value = False Then EstimateWatermarkButton.ForeColor = vbWhite
    If EstimateWatermarkButton.Value = False Then Call DeleteEstimateWatermark

End Sub
 
Upvote 0
Still do not understand.
If Toggle button is true run a script.
If Toggle button is False Delete the button
Is that what your asking for?
 
Upvote 0
Still do not understand.
If Toggle button is true run a script.
If Toggle button is False Delete the button
Is that what your asking for?
I'm not a VBA expert. I google for what I'm looking for, and Frankenstein the answer.
The EstimateWatermark and DeleteEstimateWatermark are separate macros, one to add a formatted shape (a watermark) and then to delete the shape.
So trying to have the toggle button add/remove the watermark on clicking.
I'm sure it's something stupid I've missed, but getting a Compile error. Expected variable or procedure, not module. when clicking the toggle either way.
 
Upvote 0
'Tis my own fault. I had named the module and sub by two different names, and then at some point in time, renamed the module to the same name as the sub.
 
Upvote 0
Solution
'Tis my own fault. I had named the module and sub by two different names, and then at some point in time, renamed the module to the same name as the sub.
Glad to see you have it sorted out
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,012
Members
449,280
Latest member
Miahr

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