Ich habe hatte ein Tabellenblatt was gedruckt wird, da sich die Anzahl der Spalten verändert, habe ich eine Funktion, das bis zur letzten beschriebenen Zeile gedruckt und als PDF exportiert wird.
Nun möchte ich das auf ein weiteres Tabellenblatt so erweitern, das dieses direkt unter das erste Tabellenblatt
gedruckt und auch als PDF exportiert wird.
Leider habe ich in VBA keine/kaum Ahnung, sodass ich dabei auf Hilfe angewiesen bin.
Hier der Code der aktuell im Einsatz ist.
Sheets("Tabelle1").Activate
Range("A16:H109").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
'With Selection.Borders(xlInsideVertical)
' .LineStyle = xlContinuous
' .ColorIndex = 0
' .TintAndShade = 0
' .Weight = xlThin
'End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A16:A109").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("H16:H109").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Dim LoI As Long ' Schleifenvariable
Dim LoLetzte As Long ' Variable für letzte Zeile
' letzte Zeile unabhängig von Excelversion für Spalte I (9)
LoLetzte = IIf(IsEmpty(Cells(Rows.Count, 1)), _
Cells(Rows.Count, 1).End(xlUp).Row, Rows.Count)
For LoI = LoLetzte To 2 Step -1
If Cells(LoI, 1) Empty Then Exit For
Next LoI
' Druckbereich festlegen
ActiveSheet.PageSetup.PrintArea = "$A$1:$H$" & LoI
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"U:\Groups\KWCommon\Daten\Karte\" & Worksheets("Tabelle1").Range("P14") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True