Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Loop QUESTION to end of data range... | Excel Worksheet Functions | |||
Loop QUESTION to end of data range... | Excel Worksheet Functions | |||
Loop QUESTION to end of data range... | Excel Worksheet Functions | |||
Add a Range to an existing Range in a loop? | Excel Programming | |||
Loop in a Range | Excel Programming |