ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   change the value of togglebuttons (https://www.excelbanter.com/excel-programming/316257-change-value-togglebuttons.html)

Nelson

change the value of togglebuttons
 
Hello, I have a sheet with 120 toggle buttons.
What code can I write to turn the value of all buttons to true at the same
time?
I need something like this (which does not work :P):
dim i as integer

for i = 1 to 120

togglebutton & i.value = true

next i

thank you in advance


Doug Glancy

change the value of togglebuttons
 
Nelson,

Two ways - the first does all togglebuttons regardless of name, 2nd does
ToggleButton1, ToggleButton2, etc.:

Sub test()
Dim obj As OLEObject
Dim tbutton As ToggleButton

For Each obj In Worksheets("Sheet1").OLEObjects
If TypeOf obj.Object Is ToggleButton Then
Set tbutton = obj.Object
tbutton.Value = True
End If
Next obj
End Sub

Sub test2()
Dim obj As OLEObject
Dim i As Integer

For i = 1 To 120
Worksheets("Sheet1").OLEObjects("ToggleButton" & i).Object.Value = True
Next i
End Sub

hth,

Doug Glancy

"Nelson" wrote in message
...
Hello, I have a sheet with 120 toggle buttons.
What code can I write to turn the value of all buttons to true at the same
time?
I need something like this (which does not work :P):
dim i as integer

for i = 1 to 120

togglebutton & i.value = true

next i

thank you in advance





All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com