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-Key: 23607601790

Url: https://administrator.de/contentid/23607601790

Printed on: June 18, 2024 at 02:06 o'clock

Member: michi1983
Solution michi1983 Oct 25, 2023 at 13:22:26 (UTC)
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ß
Member: jkrbrv
jkrbrv Nov 01, 2023 at 07:41:26 (UTC)
Goto Top
Hallo Michi1983,
hat super geklappt, besten Dank.