Excel VBA to Export as a PDF multiple ranges

shophoney

Active Member
Joined
Jun 16, 2014
Messages
286
Hi,

I need to export as a PDF multiple ranges on a single sheet.

I would like to export A2:E55, Then G2:to the end of J ??, K2: to end of Q.

The range can vary depending on the period I select for the data in the pivot tables.

I don't want to have to keep selecting the range and make multiple separate PDF files.

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this macro.
VBA Code:
Public Sub Create_PDF()
     
    Dim PDFfileName As String
    Dim lastJ As Long, lastQ As Long
    Dim PDFranges As Range
    
    PDFfileName = ThisWorkbook.Path & "\Multiple ranges.pdf"
    
    With ActiveSheet
        lastJ = .Cells(.Rows.Count, "J").End(xlUp).Row
        lastQ = .Cells(.Rows.Count, "Q").End(xlUp).Row
        Set PDFranges = .Range("A2:E55,G2:J" & lastJ & ",K2:Q" & lastQ)
    End With
    
    PDFranges.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfileName, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
     
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top