Export specific sheet(s) based on cell values into single Pdf

Belalhp

New Member
Joined
Oct 18, 2018
Messages
4
Hello... I'm having some difficulties... your help regarding the matter will be highly appreciated.

I have around 100 plus worksheets. 1st sheet is the Summery Sheet, in column B I have worksheet names and based on the value in column G I want to print that worksheet.
If column G has “Y” value (e.g. in G2, G3 & G5) then the relevant worksheets (e.g. worksheet names mentioned in B2, B3 & B5) will be exported as single PDF file (named “Print”).

ABCDEFG
SL .No. Work Sheet NamePrint Status
1Summery Sheet
2A One Polymer LtdY
3Altech Aluninium Industries LtdY
4Building Product & Service
5Arif Kabir EnterpriseY

<tbody>
</tbody>

I got the below VBA from another website (extendoffice) which only exports 1 sheet (last “Y”) rather than all the “Y”.

Code:
[COLOR=#000080]Sub CreateControlSheet()
'UpdatebyExtendoffice20170811
    Dim i As Integer
    Dim xCSheetRow As Integer
    Dim xSName As String
    Dim xCSheet As Variant
    Dim xRgVal As String
    On Error Resume Next
    xSName = "Summery Sheet"
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set xCSheet = ActiveWorkbook.Worksheets(xSName)
    xCSheetRow = xCSheet.Range("G65536").End(xlUp).Row
    For i = 2 To xCSheetRow
        xRgVal = xCSheet.Range("G" & i).Value
        If xRgVal = "Y" Or xRgVal = "y" Then
            If xCSheet.Range("B" & i).Value <> "" Then
                ActiveWorkbook.Worksheets(xCSheet.Range("B" & i).Value).Select
                ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                "C:\Users\Accounts\Desktop\Print.pdf", Quality:= _
                xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
                Sheets("Summery Sheet").Select
            End If
        End If
    Next
    Sheets("Summery Sheet").Select
    Range("G2:G500").Select
    Selection.Replace What:="y", Replacement:="C", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("G1").Select
    Application.ScreenUpdating = True
End Sub[/COLOR]

Thanks in advance for your time.
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Remove this line
Code:
[COLOR=#000080]On Error Resume Next[/COLOR]
and see what happens. I suspect that you get an error, if so what does the error message say & what line is highlighted if you click debug
 
Upvote 0
No error occurred, I got a PDF file named Print in Desktop as usual which has only 1 page (the last sheet where I entered “y”).
 
Upvote 0
Ok, you're not changing the name of the Pdf file, so that it's just overwriting itself everytime
 
Upvote 0
Try making this change
Code:
            If xCSheet.Range("B" & i).Value <> "" Then
                ActiveWorkbook.Worksheets(xCSheet.Range("B" & i).Value).Select
                ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
                "C:\Users\Accounts\Desktop\Prin[COLOR=#0000ff]t " & i & ".[/COLOR]pdf", Quality:= _
                xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
                Sheets("Summery Sheet").Select
            End If
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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