• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

If Me.OptionButton1.Value = True Then

vasim

Member
If Me.OptionButton1.Value = True Then

Sheets("Sheet1").OptionButton1.Value = True

Sheets("Sheet2").OptionButton1.Value = True

Sheets("Sheet3").OptionButton1.Value = True

Sheets("Sheet4").OptionButton1.Value = True

Sheets("Sheet5").OptionButton1.Value = True

End If


End Sub


can this be made to an eaiser format. I want to look in everysheet, if the sheet has an option/radio button named optionbutton1 make it true,


There are only two radio buttons.
 
How about this?

[pre]
Code:
If Me.OptionButton1.Value Then 'No need to check for true value, acts like boolean
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
ws.OptionButton1.Value = True
Next ws
On Error GoTo 0
[/pre]
 
Thanks Luke, but it shows Compile error method or data member name not found and ws.Optionbutton2.value = true is highlighted (next sentence from where the loop starts)


When typing ws.o (OLEobjects) is displayed in the dropdown but no optionbutton1.

Kindly help
 
Oops, you're right. Should be:

ws.Shapes("OptionButton1").Value = True


Make sure that really is the "exact" name, with no spaces.
 
Sorry Luke Still not working. Noting happens

Ws.shapes(“Optionbutton1).

Value isn’t listed in the dropdown box available, I tried using OLEObjects instead of shapes but still no gain. Any further help.
 
Thanks Hui I already have it... here is the whole code but still not working here is what i got with the help of Luke


Private Sub OptionButton1_Click()


Dim ws As Worksheet


If Me.OptionButton1.Value Then

On Error Resume Next

For Each ws In ThisWorkbook.Worksheets

ws.OLEObjects("Optionbutton1").Value = True ' Notworking

' ws.Shapes("Optionbutton1").Value = True Not working

Next ws

On Error GoTo 0

'Sheets("Sheet1").OptionButton1.Value = True

End If


End Sub
 
try this line:


ws.shapes("OptionButton1").controlformat.value=checked


this should work for option buttons which are added as form controls, if you added an activex option button, it will be different
 
this should do it


Sub ActiveXTest()

Dim ws As Worksheet


For Each ws In Worksheets

On Error Resume Next

Worksheets(ws.Name).OptionButton1.Value = False

On Error GoTo 0

Next

End Sub
 
Back
Top