change the value of togglebuttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top