Borrar formato en esta macro

Para Dante amor, en esta macro que me desarrollaste me gustaría que aparte de borrar el contenido borrara el formato de las celdas. 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

1 respuesta

Respuesta
1

Pero la macro que pusiste no borra; lo que hace es copiar unas filas de una hoja a otra. Tal vez es otra macro.

Disculpa Dante, la macro correcta es esta

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

Primero borra las celdas donde se van a copiar unas filas de otra hoja, pero lo que quisiera es que antes de copiar las filas borre los formatos donde va a copiar esas filas.

Cambia esta línea:

H3.Range("A4:N" & u3). ClearContents

Por esta:

H3.Range("A4:N" & u3). Clear

Prueba y me comentas si es lo que necesitas.

Si es lo que necesitas, r e cuerda valorar la respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas