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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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