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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,723
Messages
6,174,123
Members
452,546
Latest member
Rafafa

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