Macro para Buscar un Registro y Eliminarlos continuación 2

el error lo da en set B=

No logro hacer que funcione.

Espero me puedas ayudar en dejarla junta la búsqueda y el borrado y también separada así:

Un botón para que busque y borre.

Y otro botón para que solo busque

Y otro botón para que sierre.

Sub buscarxx()
 '//Todoexpertos
 '[Por Adriel Ortiz
 '
 ' Application.ScreenUpdating = False
 Application.DisplayAlerts = False
 '
    Set l1 = ThisWorkbook
    Set h1 = l1.Sheets("buso")
    '
    ruta = "C:\Users\JOSE\Desktop\TODO ESCRITORIO\menu\"
    libro2 = "libro2.xlsx"
    '
    Set l2 = Workbooks.Open(Filename:=ruta & libro2)
    Set h2 = l2.Sheets("Hoja1")
    u = h2.Range("A" & Rows.Count).End(xlUp).Row
    Set B = h2.Range("A8:A" & u).Find(h1.Range("D21"), lookat:=xlWhole)
    If Not B Is Nothing Then
        If MsgBox("Desea eliminar el registro: " & h2.Cells(B.Row, "A") _
            , vbQuestion & vbYesNo, "ELIMINAR") = vbYes Then _
            h2.Rows(B.Row).Delete
    l2.Save
    l2.Close False
    MsgBox "fin"
    Else
        MsgBox "El código buscado no existe", vbCritical
        h1.Range("D21").Select
    End If
    '
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

1 respuesta

Respuesta
1

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas