View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Variable as name of object does not work - Why?

and it they are option buttons from the control toolbox toolbar as opposed
to the forms toolbar (as illustrated by KL), you would use

Sub MySub()
Dim i As Long
For i = 1 To 200
Activesheet.OleObjects("OptionButton" & i).Object.Value = False
Next i
End Sub

--
Regards,
Tom Ogilvy



"KL" wrote in message
...
Hi JEFF,

Problem is you're trying to use the name of the optionbutton (a string) as
if it were the object (optionbutton) itself. Also, the functions CStr and
Trim aren't necessary here. Try this:

Sub MySub()
Dim i As Long
For i = 1 To 200
OptionButtons("OptionButton" & i).Value = False
Next i
End Sub

Regards,
KL


"-JEFF-" wrote in message
...
While trying to make changes to a large number of option buttons on a
sheet,
I want to increment a number and concactinate it in order to change the
correct optionbutton. But this does not work:

Sub MySub
dim i
i = 1
for i = 1 to 200
MyOB = "OptionButton" & trim(str(i))
MyOB.value = False 'or any of the other properties I need to change
next i
end

It does work when I use the actual optionbutton name instead of the
variable, i.e. OptionButton2.value = False
-JEFF-