¿Cómo modifico esta macro para insertar un salto de página una fila antes?

Estimado Dante, encontré esta macro de tu autoría, mi pregunta es cómo modificarla para que el salto de página se inserte una fila más arriba de la celda que contiene "ANALISIS DE PRECIO UNITARIO" y no en esa misma celda, o bien como insertarla debajo de cierto contenido? De antemano muchas gracias. @aprendemos

Sub salto()
'Por.DAM
una = False
t = 0
hoja = 760
n = 1
Application.ScreenUpdating = False
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.ResetAllPageBreaks
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
    If Cells(i, "A") = "ANÁLISIS DE PRECIO UNITARIO" Then
        If una Then
            ActiveSheet.HPageBreaks.Add Cells(i, "A")
            t = Rows(i).Top
            Set ActiveSheet.HPageBreaks(n).Location = Cells(i, "A")
            n = n + 1
        End If
        una = True
    End If
    dif = Rows(i).Top - t
    If dif >= hoja Then
        If Cells(i, "A") = "" Then
            For k = i To 1 Step -1
                If Cells(k, "A") <> "" Then
                    j = k
                    Exit For
                End If
            Next
        Else
            j = i
        End If
        ActiveSheet.HPageBreaks.Add Cells(j, "A")
        t = Rows(j).Top
        Set ActiveSheet.HPageBreaks(n).Location = Cells(j, "A")
        n = n + 1
    End If
Next
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = True
End Sub

3 respuestas

Respuesta
1

Estimado Dante te envié a tu correo el archivo.

Respuesta
1

¿A qué te refieres con más arriba?

Es decir, si la celda A50 contiene "ANALISIS DE PRECIO UNITARIO", ¿en dónde quieres el salto de página en la A51 o en la A49?

Tendría que ver tu archivo para hacer pruebas, envíame tu archivo, en una hoja me pones el ejemplo de cómo tienes tu información y en otra hoja me pones como necesitas el resultado.

Te anexo la macro actualizada:

Sub salto()
'Por.DAM
    una = False
    t = 0
    hoja = 760
    n = 1
    Application.ScreenUpdating = False
    ActiveWindow.View = xlPageBreakPreview
    ActiveSheet.ResetAllPageBreaks
    For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
        If Cells(i, "A") = "ANÁLISIS DE PRECIO UNITARIO" Then
            If una Then
                ActiveSheet.HPageBreaks.Add Cells(i - 1, "A")
                t = Rows(i).Top
                Set ActiveSheet.HPageBreaks(n).Location = Cells(i - 1, "A")
                n = n + 1
            End If
            una = True
        End If
        dif = Rows(i).Top - t
        If dif >= hoja Then
            If Cells(i, "A") = "" Then
                For k = i To 1 Step -1
                    If Cells(k, "A") <> "" Then
                        j = k
                        Exit For
                    End If
                Next
            Else
                j = i
            End If
            ActiveSheet.HPageBreaks.Add Cells(j, "A")
            t = Rows(j).Top
            Set ActiveSheet.HPageBreaks(n).Location = Cells(j, "A")
            n = n + 1
        End If
    Next
    ActiveWindow.View = xlNormalView
    Application.ScreenUpdating = True
End Sub

Saludos.Dante Amor

Recuerda valorar la respuesta.

Respuesta

¿Cómo podría utilizar esta macro para todas las hojas?

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas