jkrbrv
Goto Top

Seitenumbruch per VBA in Excel

Hallo,
ich habe in einer Excel-Tabelle in Spalte A immer die die Bezeichnung
"page-break-after" stehen. An dieser Stelle möchte ich jetzt einen Seitenumbrucg durchführen.
Dies sollte über einen VBA Code gelöste werden, da diese Tabelle monatlich wiederkommt.
Ich hoffe einer hat eine Idee dafür. Ich habe leider keine.
Danke.

Content-ID: 23607601790

Url: https://administrator.de/forum/seitenumbruch-per-vba-in-excel-23607601790.html

Ausgedruckt am: 01.04.2025 um 13:04 Uhr

michi1983
Lösung michi1983 25.10.2023 um 15:22:26 Uhr
Goto Top
Hallo,

Sub InsertPageBreaks()
    Dim LastRow As Long
    Dim ws As Worksheet
    Dim Cell As Range

    ' Set the worksheet where you want to insert page breaks  
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name  

    ' Find the last row with data in column A  
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row  

    ' Loop through each cell in column A  
    For Each Cell In ws.Range("A1:A" & LastRow)  
        If Cell.Value = "page-break-after" Then  
            ' Insert a page break after the cell  
            ws.HPageBreaks.Add Before:=Cell.Offset(1, 0)
        End If
    Next Cell
End Sub

Gruß
jkrbrv
jkrbrv 01.11.2023 um 08:41:26 Uhr
Goto Top
Hallo Michi1983,
hat super geklappt, besten Dank.