Explicación de funcionamiento de esta macro para copiar filas a otra hoja con condición
Para Dante Amor.
Buenos días. Te adjunto una macro que me creaste y que funciona a la perfección. Con el ánimo de seguir aprendiendo macros en Excel, me gustaría que me explicaras con detalle por líneas cómo funciona, especialmente las líneas en negrita, pues me pierdo un poco en la sintaxis.
Muchas gracias
Sub CopiarFilas()
'Por.Dante Amor
Set h1 = Sheets("Datos")
Set h2 = Sheets("Q1")
Set h3 = Sheets("Territorio")
'
u3 = h3.Range("B" & Rows.Count).End(xlUp).Row + 1
If u3 < 4 Then u3 = 4
h3.Range("A4:N" & u3).ClearContents
dato = h1.[C1]
If dato = "" Then
MsgBox "Falta la condición a buscar en la hoja " & h1.Name
Exit Sub
End If
'
Set r = h2.Range("B4:B" & h2.Range("B" & Rows.Count).End(xlUp).Row)
Set b = r.Find(dato, lookat:=xlWhole)
If Not b Is Nothing Then
celda = b.Address
Do
'detalle
u3 = h3.Range("B" & Rows.Count).End(xlUp).Row + 1
If u3 < 4 Then u3 = 4
h2.Range("A" & b.Row & ":N" & b.Row).Copy h3.Range("A" & u3)
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> celda
End If
MsgBox "Filas copiados"
End Sub