OptionButton y textbox dentro de un grupo en formulario vba
Estimados expertos:
Tengo un inconveniente con un formulario en vba y no sé como resolverlo.
Tengo una serie de preguntas (24 en total) pero cada pregunta forma parte de un grupo dónde en algunas hay dos optionbutton (SI y NO) y un textbox que de responder a la pregunta con SI, entonces deben completar un número o un texto según corresponda y en caso de responder que no salta a la pregunta siguiente.
También hay algunas preguntas (dos de ellas) que tienen un botón dentro del grupo y dos optionbutton que en caso de responder SI entonces deben abrir otro formulario para completar y de responder NO saltaría a la siguiente pregunta.
Estos formularios que se abren también tienen preguntas organizadas por grupos y responden con checkbox o con cuadro de lista.
Mi inconveniente es el siguiente:
Adjunto el código que armé para completar la tabla del primer formulario que funciona, pero si respondo SI, me dá FALSO y además completa la totalidad de las filas, algo está mal en el código que no completa una sola fila sino que lo hace indefinidamente.
Por otro lado no encuentro como completar la tabla desde el grupo, es decir que se complete una columna con el optionbutton y otra con el textbox, ambos en el mismo grupo y lo mismo me pasa con el checkbox y con el cuadro de lista.
Podrían ayudarme? Desde ya, muchas gracias.
Va el código que hasta el momento funciona entre "" porque me pone FALSO cuando respondo SI
y sólo contempla hasta ahora el optionbutton, no sé como asociar el textbox.
Private Sub BotonGrabarDatos_Click()
Dim obj As Object
Dim grupo1 As Boolean
Dim grupo2 As Boolean
Dim grupo5 As Boolean
Dim grupo6 As Boolean
Dim grupo7 As Boolean
Dim grupo8 As Boolean
Dim grupo9 As Boolean
Dim grupo10 As Boolean
Dim grupo11 As Boolean
Dim grupo12 As Boolean
Dim grupo13 As Boolean
Dim grupo14 As Boolean
Dim grupo15 As Boolean
Dim grupo16 As Boolean
Dim grupo17 As Boolean
Dim grupo18 As Boolean
Dim grupo19 As Boolean
Dim grupo20 As Boolean
Dim grupo21 As Boolean
Dim grupo22 As Boolean
Dim grupo23 As Boolean
Dim grupo24 As Boolean
Dim ultimafila As Double 'Variable que almacena el valor en la última fila libre
'Escanear a través de cada objeto activo
For Each obj In ActiveDatosPMI.OLEObjects
Set obj = obj.Object
'Analizar para verificar que es un botón de opción
If TypeOf obj Is MSForms.OptionButton Then
'Pruebe a ver si el optionbutton es cierto y en uno de los grupos
If obj.GroupName = "grupo1" And obj.Value = True Then
RingStent = True
End If
If obj.GroupName = "grupo2" And obj.Value = True Then
FenNum = True
End If
If obj.GroupName = "grupo5" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo6" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo7" And obj.Value = True Then
RingStent = True
End If
If obj.GroupName = "grupo8" And obj.Value = True Then
FenNum = True
End If
If obj.GroupName = "grupo9" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo10" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo11" And obj.Value = True Then
RingStent = True
End If
If obj.GroupName = "grupo12" And obj.Value = True Then
FenNum = True
End If
If obj.GroupName = "grupo13" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo14" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo15" And obj.Value = True Then
RingStent = True
End If
If obj.GroupName = "grupo16" And obj.Value = True Then
FenNum = True
End If
If obj.GroupName = "grupo17" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo18" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo19" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo20" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo21" And obj.Value = True Then
RingStent = True
End If
If obj.GroupName = "grupo22" And obj.Value = True Then
FenNum = True
End If
If obj.GroupName = "grupo23" And obj.Value = True Then
HookNum = True
End If
If obj.GroupName = "grupo24" And obj.Value = True Then
HookNum = True
End If
End If
Next
Range("A:A") = grupo1
Range("B:B") = grupo2
Range("E:E") = grupo5
Range("G:G") = grupo6
Range("I:I") = grupo7
Range("K:K") = grupo8
Range("M:M") = grupo9
Range("O:O") = grupo10
Range("Q:Q") = grupo11
Range("S:S") = grupo12
Range("U:U") = grupo13
Range("W:W") = grupo14
Range("Y:Y") = grupo15
Range("AA:AA") = grupo16
Range("AC:AC") = grupo17
Range("AF:AF") = grupo18
Range("AJ:AJ") = grupo19
Range("AK:AK") = grupo20
Range("AM:AM") = grupo21
Range("AO:AO") = grupo22
Range("AR:AR") = grupo23
Range("BB:BB") = grupo24
ultimafila = ActiveDatosPMI.UsedRange.Row - 1 + ActiveDatosPMI.UsedRange.Row.Count
Cells(ultimafila + 1, 1) = grupo1
Cells(ultimafila + 1, 2) = grupo2
Cells(ultimafila + 1, 5) = grupo5
Cells(ultimafila + 1, 7) = grupo6
Cells(ultimafila + 1, 9) = grupo7
Cells(ultimafila + 1, 11) = grupo8
Cells(ultimafila + 1, 13) = grupo9
Cells(ultimafila + 1, 15) = grupo10
Cells(ultimafila + 1, 17) = grupo11
Cells(ultimafila + 1, 19) = grupo12
Cells(ultimafila + 1, 21) = grupo13
Cells(ultimafila + 1, 23) = grupo14
Cells(ultimafila + 1, 25) = grupo15
Cells(ultimafila + 1, 27) = grupo16
Cells(ultimafila + 1, 29) = grupo17
Cells(ultimafila + 1, 32) = grupo18
Cells(ultimafila + 1, 36) = grupo19
Cells(ultimafila + 1, 37) = grupo20
Cells(ultimafila + 1, 39) = grupo21
Cells(ultimafila + 1, 41) = grupo22
Cells(ultimafila + 1, 44) = grupo23
Cells(ultimafila + 1, 54) = grupo24
End Sub