Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Set optionbutton with range data doing Loop//For Each

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!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rog Rog is offline
external usenet poster
 
Posts: 18
Default Set optionbutton with range data doing Loop//For Each

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



"lecaballero" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Set optionbutton with range data doing Loop//For Each


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

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



"lecaballero" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 2 December 4th 06 09:25 PM
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 2 December 4th 06 05:19 PM
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 0 December 4th 06 03:59 PM
Add a Range to an existing Range in a loop? Mick Excel Programming 3 June 18th 05 06:12 AM
Loop in a Range aksel børve Excel Programming 2 March 8th 05 06:40 PM


All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"