Good day,
pls find attached bellow code. Now it is saving based on J4 value, but would like as per my previous post. Many thanks for help.
Sub forfiett()
Dim i As Long, printrange As Range, x As Long, y As Long
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
For i = Range("J" & Rows.Count).End(3).row To 1 Step -1
If Cells(i, "J") <> Cells(i + 1, "J") Then
Rows(i + 1).Resize(2).Insert
End If
Next i
For Each printrange In Range("J2:J" & Range("J" & Rows.Count).End(3).row + 1).SpecialCells(2, 2).Areas
x = printrange.Cells(1, 1).row
y = printrange.Cells(1, 1).End(4).row
If Cells(x + 1, "C") = "" Then y = y - 2
If y >= x + 2 Then
With ActiveSheet.PageSetup
.PrintArea = Range(Cells(x, "A"), Cells(y, "AE")).Address
.Orientation = xlLandscape
.PrintTitleRows = "$1:$1"
End With
call save_PDF
Else
y = x + 1
With ActiveSheet.PageSetup
.PrintArea = Range(Cells(x, "A"), Cells(y, "AE")).Address
.Orientation = xlLandscape
.PrintTitleRows = "$1:$1"
End With
call save_PDF
End If
Next printrange
Range("J2:J" & Range("J" & Rows.Count).End(3).row).SpecialCells(4).EntireRow.Delete
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = xlCalculationManual
End With
End Sub
Sub save_PDF()
Dim SH As Worksheet
Dim sStr As String
Const myPath As String = "C:\Documents\Test\"
Set SH = ActiveSheet
sStr = SH.Range("J4").Value & ".pdf"
SH.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=myPath & sStr, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
Bookmarks