Para DA como hago para que al no ingresar datos en un campo de buscar no me mande a error y me pida que ingrese registro

Tengo un formulario que va por etapas, me ingresa datos y los busca para seguir ingresando por filas. Lo que ocurre ahora es que si no pongo ningún registro en el buscador me manda un mensaje que pide ingresar un registro pero luego se va a error 1004: error definido por la aplicación o el objeto. Y no logro descifrar qué es lo que le pasa ya que al cambiar los end if arreglo ese error pero no funciona el buscador. ¿Cómo puedo validar que este vacío el campo y así siga funcionando?

1 respuesta

Respuesta
2

H o l a:

Puedes poner al principio algo como esto:

    If TextBox1 = "" Then
        MsgBox "Ingresar Número de Rol", vbExclamation
        TextBox1.SetFocus
        Exit Sub
    End If

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

Te anexo el código para buscar el número de Rol; si lo encuentra selecciona la fila, si no lo encuentra te pregunta si lo quieres ingresar; si presionas Sí, te abre el formulario1, si presionas No, termina la ejecución.

Private Sub CommandButton8_Click()
    'Application.ScreenUpdating = False
    If TextBox1 = "" Then
        MsgBox ("Debe ingresar un número de rol")
        TextBox1.SetFocus
        Exit Sub
    End If
    '
    Sheets("Seguimiento").Select 'selecciona la hoja "Seguimiento"
    Dim fila As Integer
    fila = 1
    On Error Resume Next ' se salta el error del buscar en caso de que no encuentre el valor
    Set h = ActiveSheet
    Set b = h.Columns("B").Find(TextBox1, lookat:=xlWhole)
    'Columns("B:B").Select ' buscar en la columna
    '    Selection.Find(What:=TextBox1.Value, After:=ActiveCell, LookIn:=xlFormulas _
            , lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
    '
    If b Is Nothing Then
        res = MsgBox("No existe el Número de Rol: " & TextBox1 & vbCr & _
                     "Desea ingresarlo", vbQuestion + vbYesNo, "INGRESAR NÚMERO DE ROL")
        If res = vbYes Then
            Unload Me
            UserForm1.Show
        End If
        Exit Sub
    End If
    '
    Cells(b.Row, "B").Select
    fila = ActiveCell.Row
    If fila <> 1 Then
        Dim i As Integer
        Dim etapa As Integer
        'Valida etapa 2
        For i = 10 To 13
            If Cells(fila, i) = "" Then
            etapa = 2
            GoTo Final
            End If
        Next i
        'Valida etapa 3
        If Cells(fila, 16) = "" Then
            etapa = 3
            GoTo Final
        End If
        'Valida etapa 4
        If Cells(fila, 19) = "" Then
            etapa = 4
            GoTo Final
        End If
        'Valida etapa 5
        If Cells(fila, 26) = "" Then
            etapa = 5
            GoTo Final
        End If
        'Valida etapa 6
        If Cells(fila, 38) = "" Then
            etapa = 6
            GoTo Final
        End If
        'Valida etapa 7
        If Cells(fila, 50) = "" Then
            etapa = 7
            GoTo Final
        Else
            etapa = 8
            GoTo Final
        End If
    End If
    'If fila = 1 Then
    '    res = MsgBox("No existe el Número de Rol: " & TextBox1 & vbCr & _
    '                     "Desea ingresarlo", vbQuestion + vbYesNo, "INGRESAR NÚMERO DE ROL")
    '        If res = vbYes Then
    '            UserForm1.TextBox2 = Me.TextBox1
    '            UserForm1.TextBox2.Locked = True
    '            Unload Me
    '            UserForm1.Show
    'End If
Final:
    If fila <> 1 Then
        If etapa = 2 Then
            Cells(fila, 3) = "Da Inicio"
            UserForm2.Show
        ElseIf etapa = 3 Then
            Cells(fila, 3) = "Da Inicio"
            UserForm3.Show
        ElseIf etapa = 4 Then
            Cells(fila, 3) = "En Proceso"
            UserForm4.Show
        ElseIf etapa = 5 Then
            Cells(fila, 3) = "En Proceso"
            UserForm5.Show
        ElseIf etapa = 6 Then
            Cells(fila, 3) = "En Proceso"
            UserForm6.Show
        ElseIf etapa = 7 Then
            Cells(fila, 3) = "En Proceso"
            UserForm7.Show
        ElseIf Cells(fila, 19) = "NO" Then
            Cells(fila, 3) = "Anulado"
            Cells(fila, 50) = "NO"
            Cells(fila, 26) = "NO"
            Cells(fila, 38) = "NO"
            MsgBox ("Proceso Anulado"), vbInformation
        ElseIf Cells(fila, 50) = "NO" Then
            Cells(fila, 3) = "Anulado"
            MsgBox ("Proceso Anulado"), vbInformation
        Else: Cells(fila, 3) = "Ajuste Final"
            MsgBox ("Ajuste Final: Proceso Terminado"), vbInformation
        End If
    End If
    TextBox1 = Empty
    Range("A5").Select
    Application.ScreenUpdating = True
    Me.Hide
End Sub

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

¡Gracias!  Creo que con eso arreglaste mi planilla ? La probé con tu código en el formulario en vez de mi buscador y no manda a error y busca hasta los datos de un dígito 

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas