Set optionbutton with range data doing Loop//For Each

G

Guest

Hi all,

First of all thanks you a lot, I am learning a lot from the people who helps
here!

I need to do a questionnire and I have designed a userform. Each answer has
4 optionbuttons to choose among 4 answers. There is 15 questions and I want
that anyone can see which option has been selected.

B c d e f g h i j
k l
Sup Ext Name Day ............... until 15 questions.........
1 3 aab
2 2 aac
3 1 aad <- Those are the answers
2 1 acd


To do that I have set this code:

If ActiveCell = 1 Then
optSup1 = True
ElseIf ActiveCell = 2 Then
optSup2 = True
ElseIf ActiveCell = 3 Then
optSup3 = True
Else
optSup4 = True
End If

So If in the cell there is a 1, I want the optSup1 to be checked, if its is
a 2 in the cell I need the optSup2 to be chosen and so on.

The problem is that the interview is going to be done several times and
there is a lot of questions and I need to do that with a loop. Could It be
possible to do something like that?



Dim i as integer




For i=1 to 5

If ActiveCell = i Then
optSup & i = True
Else
Exit Sub
End If

Next i


The problem is that a variable can not be concatenated and if I add quotes
the VBA does not recognize it as a variable.

Sorry if my english level is not very good

Thanks a lot in advance!!!
 
G

Guest

Hi

Assuming your option buttons have the same prefix, eg in my example were
"opt1","opt2","opt3" & "opt4", then you can do something like this to switch
the values :

Controls("opt" & num).value=true

where num is a variable holding the value 1-4

regards

Rog
 
G

Guest

Thanks a lot Rog!!!

It is so simple that is beautiful!!

I really dont know very much of controls an variables in macros, but i'm
learning very quickly because of you

Thank you for everything, you saved me like 1 work day



"Rog" escribió:
 

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