Modificar macro para ejecutarla desde la hoja2 y no desde la hoja1 donde están los datos

Tengo la siguiente macro la cual me copia desde la hoja1 toda la filas que cumplen con una condición solicitada en la hoja2

Necesito modificarla de manera que desde la hoja2 haga la misma función, y no estar en la hoja1 para poder ejecutarla

Esta es la macro actual

Sub buscar()
filalibre = Sheets("hoja2").Range("m65000").End(xlUp).Row + 1
dato = InputBox("que dato buscamos???")
If dato = "" Then Exit Sub
Set buscado = ActiveSheet.Range("m1:m" & Range("m65000").End(xlUp).Row).Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not buscado Is Nothing Then
ubica = buscado.Address
do
buscado.EntireRow.Copy Destination:=Sheets("hoja2").Cells(filalibre, 1)
filalibre = filalibre +1
Set buscado = ActiveSheet.Range("m1:m" & Range("m65000").End(xlUp).Row).Findnext(buscado)
loop while not buscado is nothing and buscado.address <> ubica
End If
End Sub

1 Respuesta

Respuesta
2

H   o l a:

Te anexo la macro actualizada

Sub buscar()
'Act.Por.Dante Amor
    Set h1 = Sheets("Hoja1")
    Set h2 = Sheets("Hoja2")
    u = h2.Range("M" & h2.Rows.Count).End(xlUp).Row + 1
    dato = InputBox("Qué dato buscamos???", "CAPTURAR")
    If dato = "" Then Exit Sub
    '
    Set r = h1.Range("M:M")
    Set b = r.Find(dato, LookIn:=xlValues, lookat:=xlWhole)
    If Not b Is Nothing Then
        celda = b.Address
        Do
            b.EntireRow.Copy h2.Cells(u, "A")
            u = u + 1
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
    Else
        MsgBox "No Existe El Dato: " & dato, vbExclamation
    End If
End Sub
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas