En Macro Excel ¿Cómo funcionaria esto?

En esta macro (tu conocida) ¿Cómo funcionaria este tipo de validación de los TextBox?

Private Sub cmbInsertar_Click()
'Por.Dante Amor http://www.todoexpertos.com/preguntas/6dfdswlh5iak7bjd/correccion-para-macro-excel-para-insertar-datos-mandando-error
'Obligar a llenar las cajas del 6 al 9
    Dim vcs, vtx, i, LastRow, u
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:="By Jot@"
''''''''''''''''
    If CheckBox1 Then
        vcs = Array("TextBox6", "Textbox7", "Textbox8", "Textbox9", "Textbox10", "Textbox11")
        vtx = Array("UNA FECHA VALIDA", "EL NOMBRE DE EMPRESA", "REPESTOS PARA", "EL SERIAL MAQ/MOT", "LA MARCA", "EL MODELO/IDENT.")
        For i = LBound(vcs) To UBound(vcs)
            If Me.Controls(vcs(i)) = Empty Then
               MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "LLENAR LISTA"
              Exit Sub
            End If
        Next
''''''''''''''''
    If CheckBox1.Value = False Then
        'inserta datos empresa
        vcs = Array("TextBox1", "Textbox2", "Textbox3", "Textbox4", "Textbox5")
        vtx = Array("UN ITEM", "EL # DE PRODUCTO", "LA DESCRIPCION DEL PRODUCTO", "LA CANTIDAD", "EL # DE PAGINA")
        For i = LBound(vcs) To UBound(vcs)
            If Me.Controls(vcs(i)) = Empty Then
               MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "LLENAR LISTA"
              Exit Sub
            End If
        Next
'''''''''''''''''
        '
        Range("C8") = TextBox6  'Fecha
        Range("E8") = TextBox7  'Nombre Empresa
        Range("J8") = TextBox8  'Repuestos para
        Range("D9") = TextBox9  'Serial Maq/Mot.
        Range("G9") = TextBox10 'Marca
        Range("K9") = TextBox11 'Modelo/Ident.
        Range("D46").Value = Left(TextBox12.Value, 450) 'Notas
    Else
        'Productos
        If CheckBox2 Then
            'modifica producto
            u = ComboBox1.ListIndex + 11
        Else
            'inserta producto
            u = Range("b" & Rows.Count).End(xlUp).Row + 1
        End If
        Cells(u, "B") = TextBox1  'Item #
        Cells(u, "C") = TextBox2  'Producto #
        Cells(u, "D") = TextBox3  'Descripcion del Producto
        Cells(u, "J") = Val(TextBox4)  'Cant.
        Cells(u, "K") = TextBox5 'Pagina #
        ComboBox1.Clear
        For i = 11 To Range("B" & Rows.Count).End(xlUp).Row
            ComboBox1.AddItem Cells(i, "D")
        Next
    End If
    End If
    ActiveSheet.Protect Password:="By Jot@"
    Application.ScreenUpdating = True
    Call Limpiar
    ComboBox1 = ""
End Sub

La posible validación que está entre '''''''''''''''''''

Quisiera usar ese tipo de advertencia porque menciona solo el cuadro indicado.

Trate con SOLO el 1º y me da pero ya incluyendo el 2º también, no me da

Además de esto.

1 respuesta

Respuesta
2

H o l a:

Así quedaría:

Private Sub cmbInsertar_Click()
'Por.Dante Amor http://www.todoexpertos.com/preguntas/6dfdswlh5iak7bjd/correccion-para-macro-excel-para-insertar-datos-mandando-error
    '
    Dim vcs, vtx, i, LastRow, u, errores
    Application.ScreenUpdating = False
    errores = False
    If CheckBox1 Then
        vcs = Array("TextBox6", "Textbox7", "Textbox8", "Textbox9", "Textbox10", "Textbox11")
        vtx = Array("UNA FECHA VALIDA", "EL NOMBRE DE EMPRESA", "REPESTOS PARA", "EL SERIAL MAQ/MOT", "LA MARCA", "EL MODELO/IDENT.")
        For i = LBound(vcs) To UBound(vcs)
            If Me.Controls(vcs(i)) = Empty Then
               MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "LLENAR LISTA"
               errores = True
            End If
        Next
        If errores Then Exit Sub
        '
        If Not IsDate(TextBox6) Then
            MsgBox "Capturar una fecha válida", vbExclamation
            TextBox6.SetFocus
            Exit Sub
        End If
        '
        Range("C8") = TextBox6  'Fecha
        Range("E8") = TextBox7  'Nombre Empresa
        Range("J8") = TextBox8  'Repuestos para
        Range("D9") = TextBox9  'Serial Maq/Mot.
        Range("G9") = TextBox10 'Marca
        Range("K9") = TextBox11 'Modelo/Ident.
        Range("D46").Value = Left(TextBox12.Value, 450) 'Notas
    Else
        'Productos
        vcs = Array("TextBox1", "Textbox2", "Textbox3", "Textbox4", "Textbox5")
        vtx = Array("UN ITEM", "EL # DE PRODUCTO", "LA DESCRIPCION DEL PRODUCTO", "LA CANTIDAD", "EL # DE PAGINA")
        For i = LBound(vcs) To UBound(vcs)
            If Me.Controls(vcs(i)) = Empty Then
                MsgBox "DEBES INTRODUCIR: " & vtx(i), vbExclamation, "LLENAR LISTA"
                errores = True
            End If
        Next
        If errores Then Exit Sub
        If CheckBox2 Then
            'modifica producto
            u = ComboBox1.ListIndex + 11
        Else
            'inserta producto
            u = Range("b" & Rows.Count).End(xlUp).Row + 1
        End If
        Cells(u, "B") = TextBox1  'Item #
        Cells(u, "C") = TextBox2  'Producto #
        Cells(u, "D") = TextBox3  'Descripcion del Producto
        Cells(u, "J") = Val(TextBox4)  'Cant.
        Cells(u, "K") = TextBox5 'Pagina #
        '
        ComboBox1.clear
        For i = 11 To Range("B" & Rows.Count).End(xlUp).Row
            ComboBox1.AddItem Cells(i, "D")
        Next
    End If
    'ActiveSheet.Protect Password:="123"
    Application.ScreenUpdating = True
    TextBox1 = "": TextBox2 = "": TextBox3 = "": TextBox4 = "": TextBox5 = "": TextBox6 = "": _
    TextBox7 = "": TextBox8 = "": TextBox9 = "": TextBox10 = "": TextBox11 = "": TextBox12 = ""
    ComboBox1 = ""
End Sub

No pasa al segundo, porque cuando entra el primero, tienes la instrucción exit sub, ya se la quité y puse una variable "errores", si errores = true, entonces significa que alguno de los textbox está vacío, entonces y sólo hasta entonces, que ya se revisaron todos los textbox, se pone el Exit Sub.


sal u dos

Muy bien DAM, gracias por tu tiempo y buen fin de sábado y Domingo en paz y felicidad.

Solo por saber que pasaría le cambie (para probar como)

                errores = True
            End If
            If errores Then Exit Sub
        Next
            ''''If errores Then Exit Sub

Vi la cosa y volvi a dejar como me la entregate

Pasa lo mismo.

Quiero que sepas que califique desde hace días atrás, pregunto si te llego la calificación

Si llegó, g racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas