Alertas de búsqueda en formulario excel

Tengo el siguiente código para realizar búsquedas en un formulario, necesito que salga una ventana si el numero buscado no aparece con las opciones si y no (msgbox)

De antemano gracias por su ayuda !

Private Sub CommandButton1_Click()
'
'
ListBox1.ColumnCount = 6
Set h5 = Sheets("BILAN")
ListBox1.Clear
If TextBox1 = "" Then
MsgBox "Veuillez taper un N° série"
Exit Sub
End If
For i = 2 To h5.Range("C" & Rows.Count).End(xlUp).Row
cad = h5.Cells(i, "C")
If cad Like "*" & UCase(TextBox1) & "*" Then
existe = True
With ListBox1
.AddItem h5.Cells(i, "C")
.List(.ListCount - 1, 1) = h5.Cells(i, "D")
.List(.ListCount - 1, 2) = h5.Cells(i, "E")
.List(.ListCount - 1, 3) = h5.Cells(i, "F")
.List(.ListCount - 1, 4) = h5.Cells(i, "G")
.List(.ListCount - 1, 5) = h5.Cells(i, "K")
End With
End If
Next
End Sub

1 Respuesta

Respuesta
1

Te anexo la macro actualizada. Te puse el mensaje cuando el número no aparece con las opciones "Sí" "No", pero no pusiste qué hacer cuando presiones "Sí" o qué hacer cuando presiones "No".

Private Sub CommandButton1_Click()
'
'
    ListBox1.ColumnCount = 6
    Set h5 = Sheets("BILAN")
    ListBox1.Clear
    If TextBox1 = "" Then
        MsgBox "Veuillez taper un N° série"
        Exit Sub
    End If
    cad = ""
    existe = False
    For i = 2 To h5.Range("C" & Rows.Count).End(xlUp).Row
        cad = UCase(h5.Cells(i, "C"))
        If cad Like "*" & UCase(TextBox1) & "*" Then
            existe = True
            With ListBox1
                . AddItem h5.Cells(i, "C")
                . List(.ListCount - 1, 1) = h5.Cells(i, "D")
                . List(.ListCount - 1, 2) = h5.Cells(i, "E")
                . List(.ListCount - 1, 3) = h5.Cells(i, "F")
                . List(.ListCount - 1, 4) = h5.Cells(i, "G")
                . List(.ListCount - 1, 5) = h5.Cells(i, "K")
            End With
        End If
    Next
    If existe = False Then
        MsgBox "El número buscado no aparece", vbYesNo, "BUSCAR"
    End If
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