Como comprobar que un OptionButton se haya seleccionado

Tengo un Formulario de Captura, lo que quiero es evitar que pasen a otro formulario sin antes haber capturado todos los campos del primer formulario. Ya tengo una macro pero no están integrados en la validacion los OptionButton, no se como integrarlos a la macro es por eso que pido su ayuda.

*Tengo el OptionButton1 y OptionButton2 dentro de un marco* pero solo pueden elegir uno de los dos.

Y la macro que actualmente tengo es la siguiente:

Private Sub CommandButton2_Click()

vcs = Array("TextBox5", "Código", "Nombre", "Apellidos", "DNI", _
"ComboBox3", "ComboBox1", "ComboBox2", "TextBox9")
'
vtx = Array("fecha", "su numero de Registro", "nombre", "apellidos", "número de registro", _
"Tipo de Falla", "Aplicativo", "Dispositivo", "Posición")
'
For i = LBound(vcs) To UBound(vcs)
If Me.Controls(vcs(i)) = "" Then
MsgBox "Ingrese " & vtx(i), vbExclamation, "VALIDACIÓN CAPTURA"
Me.Controls(vcs(i)).SetFocus
Exit Sub
End If
Next
'
Worksheets("Hoja3").Select
ult1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(ult1, 1) = Nombre.Text
Cells(ult1, 2) = Apellidos.Text
Cells(ult1, 3) = DNI.Text
Cells(ult1, 4) = ComboBox3.Value
Cells(ult1, 6) = ComboBox2.Value
Cells(ult1, 5) = ComboBox1.Value
Cells(ult1, 8) = TextBox9.Text
Cells(ult1, 9) = TextBox5.Text
Cells(ult1, 10) = TextBox10.Text
If OptionButton1 Then wcap = OptionButton1.Caption
If OptionButton2 Then wcap = OptionButton2.Caption
Cells(ult1, 7) = wcap
UserForm3.Show
End Sub

2 respuestas

Respuesta
1

[Hola 

te paso la macro actualizada

Private Sub CommandButton2_Click()
'
If OptionButton1 = False And OptionButton2 = False Then
MsgBox "Seleccione un option"
Exit Sub
End If
'
vcs = Array("TextBox5", "Código", "Nombre", "Apellidos", "DNI", _
"ComboBox3", "ComboBox1", "ComboBox2", "TextBox9")
'
vtx = Array("fecha", "su numero de Registro", "nombre", "apellidos", "número de registro", _
"Tipo de Falla", "Aplicativo", "Dispositivo", "Posición")
'
For i = LBound(vcs) To UBound(vcs)
If Me.Controls(vcs(i)) = "" Then
MsgBox "Ingrese " & vtx(i), vbExclamation, "VALIDACIÓN CAPTURA"
Me.Controls(vcs(i)).SetFocus
Exit Sub
End If
Next
'
Worksheets("Hoja3").Select
ult1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(ult1, 1) = Nombre.Text
Cells(ult1, 2) = Apellidos.Text
Cells(ult1, 3) = DNI.Text
Cells(ult1, 4) = ComboBox3.Value
Cells(ult1, 6) = ComboBox2.Value
Cells(ult1, 5) = ComboBox1.Value
Cells(ult1, 8) = TextBox9.Text
Cells(ult1, 9) = TextBox5.Text
Cells(ult1, 10) = TextBox10.Text
If OptionButton1 Then wcap = OptionButton1.Caption
If OptionButton2 Then wcap = OptionButton2.Caption
Cells(ult1, 7) = wcap
UserForm3.Show
End Sub

valora la respuesta para finalizar saludos!

Respuesta
1

Te anexo la actualización

Private Sub CommandButton2_Click()
'Act.Por.Dante Amor
    'Nombre de los controles
    vcs = Array("TextBox5", "Código", "Nombre", "Apellidos", "DNI", _
                "ComboBox3", "ComboBox1", "ComboBox2", "TextBox9")
    'mensaje por control
    vtx = Array("fecha", "su numero de Registro", "nombre", "apellidos", "número de registro", _
                "Tipo de Falla", "Aplicativo", "Dispositivo", "Posición")
    '
    For i = LBound(vcs) To UBound(vcs)
        If Me.Controls(vcs(i)) = "" Then
            MsgBox "Ingrese " & vtx(i), vbExclamation, "VALIDACIÓN CAPTURA"
            Me.Controls(vcs(i)).SetFocus
            Exit Sub
        End If
    Next
    If OptionButton1 = False And OptionButton2 = False Then
        MsgBox "Selecciona una opción"
        Exit Sub
    End If
    '
    Worksheets("Hoja3").Select
    ult1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
    Cells(ult1, 1) = Nombre.Text
    Cells(ult1, 2) = Apellidos.Text
    Cells(ult1, 3) = DNI.Text
    Cells(ult1, 4) = ComboBox3.Value
    Cells(ult1, 6) = ComboBox2.Value
    Cells(ult1, 5) = ComboBox1.Value
    Cells(ult1, 8) = TextBox9.Text
    Cells(ult1, 9) = TextBox5.Text
    Cells(ult1, 10) = TextBox10.Text
    If OptionButton1 Then wcap = OptionButton1.Caption
    If OptionButton2 Then wcap = OptionButton2.Caption
    Cells(ult1, 7) = wcap
    UserForm3.Show
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas