Excel Macro to Copy Worksheets to New Workbook Based On Cell Value and Then Print Copied Sheets to PDF

cjohnson0181

New Member
Joined
Mar 29, 2018
Messages
9
All, I currently have a macro that we use to print 4 sheets to PDF. However, we are now wanting to copy only the sheets that contain data in cell C25. (If Trans Sh 1 and 2 are not " ", then copy only those two sheets and create a new workbook). I would like to be able to choose the filename and location once the macro runs rather than saving to a specific location since I'll be sharing this with a couple friends. I'm thinking you probably can't do all of this in one macro but it would be awesome if I could!

Code:
Sub SaveSpecificToPDF()
    
Dim PdfFilename As Variant


PdfFilename = Application.GetSaveAsFilename( _
InitialFileName:="GGS Transmittal 0XX", _
FileFilter:="GGS Transmittal, *.pdf", _
Title:="Save As PDF")






Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4")).Select


If PdfFilename <> False Then
    With ActiveSheet.PageSetup
        .Orientation = xlPortrait
        .PrintArea = "$A$1:$K$49"
        .Zoom = False
        .FitToPagesTall = False
        .FitToPagesWide = 1
    End With


ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=PdfFilename, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=False, _
    IgnorePrintAreas:=False, _
    From:=1, _
    To:=5, _
    OpenAfterPublish:=True
    
End If


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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