PDA

View Full Version : Sleeper: Sum and Export to PDF



zmagic
03-29-2016, 02:20 PM
Hi,

The script publishes the pdf file perfectly only improvising required is to sum the Column E and Export to pdf.



Sub S2PDF()
On Error GoTo ErrorHandler
Application.ScreenUpdating = False
Dim rng As Range
Dim rng2 As Range
Set CurrentWb = ActiveWorkbook
LastRow1 = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range(Cells(5, 1), Cells(LastRow1, 1))
Set rng2 = Range("A4:F" & LastRow1)
rng.Copy
[j5].Select
ActiveSheet.Paste
Selection.RemoveDuplicates Columns:=1, Header:=xlNo
LastRow6 = ActiveSheet.Cells(Rows.Count, 10).End(xlUp).Row
For I = 5 To LastRow6
[c2] = Cells(I, 10).Value
wbName = Cells(I, 10).Value
rng2.Select
Selection.AutoFilter
rng2.AutoFilter Field:=1, Criteria1:=Cells(I, 10).Value
Path = "D:\Rentreceipt\"
ActiveSheet.Range("B:F").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & wbName & ".pdf", _
IncludeDocProperties:=True, IgnorePrintAreas:=False
Selection.AutoFilter
[a1].Select
Next I
Range(Cells(5, 10), Cells(LastRow6, 10)).ClearContents
Exit Sub
ErrorHandler:
MsgBox "The folder D:\Rentreceipt\" & wbName & "\ does not exist. Check the path and try again."
Range(Cells(5, 10), Cells(LastRow6, 10)).ClearContents
Selection.AutoFilter
[c2] = ""
[a1].Select
End Sub