Data List Change + PDF Export on button click

StevenE06

New Member
Joined
Dec 22, 2015
Messages
18
Im really new to macros and trying to learn by looking at examples but have hit a road block here.

The excel file I am working on has 3 tabs/sheets. Sorted Data, Quarterly Data, and Data Validation.
The sorted data has a Unit Number drop down list(Data Validation list) from the DV sheet. The selection can and will change quarterly.
The list is reference is
Excel Formula:
='Data Validation'!$A:$A
because the list may grow or shrink each quarter (Company is a selectable option so it gives a total for all unit numbers)
2.JPG


I have a button next to the unit selection that will export to PDF and name the PDF based on the unit number selected.
I am trying to get the button to cycle through all the options in the list (Data Validation list) and export each one to PDF.
The cell for the drop down list is a merged cell on C6/D6
1.JPG

1713531283472.png


This is the PDF export button code I currently have


VBA Code:
Sub CreatePDF()

Dim ID As String

ID = Range("C6").Text

    ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    FileName:="C:\Documents\" + ID + ".pdf", _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

End Sub


Anyone able to help me out here?

Thank you in advance!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this macro:
VBA Code:
Public Sub Create_PDF_For_Each_Company()

    Dim DVrange As Range
    Dim companyValues As Variant, company As Variant
    
    With ActiveSheet
        Set DVrange = Range(.Range("C6").Validation.Formula1)
        With DVrange.Worksheet
            companyValues = .Range(DVrange(2), .Cells(.Rows.Count, DVrange.Column).End(xlUp)).Value
        End With
        For Each company In companyValues
            .Range("C6").Value = company
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Documents\" & company & ".pdf", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        Next
    End With

End Sub
 
Upvote 0
Solution
Hey

So it cycles through the "options" but its not pulling data when it does.

Here is what it shows when I manually drop down and select a Unit Number
1713551825897.png

However when the macro runs and it does the export on them it does them all like this
1713551863735.png
 
Upvote 0
So it cycles through the "options" but its not pulling data when it does.

Without your workbook or a more detailed explanation of the worksheet I can't explain why it's not pulling the data.

Perhaps upload a copy of your workbook or post the worksheets using the forum's XL2BB tool.
 
Upvote 0
Without your workbook or a more detailed explanation of the worksheet I can't explain why it's not pulling the data.

Perhaps upload a copy of your workbook or post the worksheets using the forum's XL2BB tool.
Hey John

I will send you a message directly as I cannot download the XL2BB tool on this computer.
 
Upvote 0

Forum statistics

Threads
1,223,877
Messages
6,175,137
Members
452,614
Latest member
MRSWIN2709

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