VBA All set value of all toggle buttons in sheet to False

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I have a sheet with 15 toggle buttons. I also have command buttons and I am trying to switch off all toggle buttons if command button is pressed. Is any way to achieve it in any shorter way than repeating this line 15 times for each command button?

VBA Code:
Me.ToggleButton1.Value = False
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,

try following & see if does what you want

VBA Code:
Sub ResetToggleButtons()

    Dim OleObj As OLEObject
    
    For Each OleObj In ActiveSheet.OLEObjects
        If TypeName(OleObj.Object) = "ToggleButton" Then
            OleObj.Object.Value = False
        End If
    Next OleObj

End Sub

I have assumed sheet with togglebuttons is the ActiveSheet when code is run if not, Replace ActiveSheet with required worksheet object.

Dave
 
Upvote 0
Solution
Hi,

try following & see if does what you want

VBA Code:
Sub ResetToggleButtons()

    Dim OleObj As OLEObject
   
    For Each OleObj In ActiveSheet.OLEObjects
        If TypeName(OleObj.Object) = "ToggleButton" Then
            OleObj.Object.Value = False
        End If
    Next OleObj

End Sub

I have assumed sheet with togglebuttons is the ActiveSheet when code is run if not, Replace ActiveSheet with required worksheet object.

Dave
Works perfectly! Thank you!
 
Upvote 0
Hi,

try following & see if does what you want

VBA Code:
Sub ResetToggleButtons()

    Dim OleObj As OLEObject
   
    For Each OleObj In ActiveSheet.OLEObjects
        If TypeName(OleObj.Object) = "ToggleButton" Then
            OleObj.Object.Value = False
        End If
    Next OleObj

End Sub

I have assumed sheet with togglebuttons is the ActiveSheet when code is run if not, Replace ActiveSheet with required worksheet object.

Dave
I just noticed I have three extra toggle buttons that have to be excluded from this group. Is it possible to do it?
 
Upvote 0
I just noticed I have three extra toggle buttons that have to be excluded from this group. Is it possible to do it?
I was able to move them to other sheet! Everything works great!
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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