variable in object name

G

Guest

I have checkboxes with names from checkbox1 to checkbox20
if I try
sub whatever()
for i=1 to 20
if checkbox(i).value=true then
do sumething
end if
next i
end sub
I get error message that sub or function not defined. How to fix that?
 
T

Tom Ogilvy

sub whatever()
for i=1 to 20
if Activesheet.OleObjects("checkbox" & i).value=true then
do sumething
end if
next i
end sub

would be an example for a checkbox from the control toolbox toolbar where
the checkboxes have names like checkbox1 to checkbox20. You haven't said
where it is from or where it is located.
 
G

Guest

These checkboxes are located in userform

Tom Ogilvy said:
sub whatever()
for i=1 to 20
if Activesheet.OleObjects("checkbox" & i).value=true then
do sumething
end if
next i
end sub

would be an example for a checkbox from the control toolbox toolbar where
the checkboxes have names like checkbox1 to checkbox20. You haven't said
where it is from or where it is located.
 
T

Tom Ogilvy

sub whatever()
for i=1 to 20
if Userform1.Controls("checkbox" & i).value=true then
do sumething
end if
next i
end sub
 
G

Guest

Thanks a lot. And my task continues :)

Tom Ogilvy said:
sub whatever()
for i=1 to 20
if Userform1.Controls("checkbox" & i).value=true then
do sumething
end if
next i
end sub
 

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

Top