Angel_Code Help
New Member
- Joined
- Oct 17, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi Everyone,
I'm extremely new to VBA coding.
My excel sheet has a data validation list in cell G4. Depending on the list value selected, the cells below use index match to get values from another sheet.
I need to figure out how to save a pdf version of this tab for every single list value.
This is the code I've pieced together so far from similar threads on this board, but this only saves a PDF file for the last option in the validation list instead of ALL the options. It's driving me crazy cause other people have claimed it works
Thanks for the help!
I'm extremely new to VBA coding.
My excel sheet has a data validation list in cell G4. Depending on the list value selected, the cells below use index match to get values from another sheet.
I need to figure out how to save a pdf version of this tab for every single list value.
This is the code I've pieced together so far from similar threads on this board, but this only saves a PDF file for the last option in the validation list instead of ALL the options. It's driving me crazy cause other people have claimed it works
Thanks for the help!
VBA Code:
Public Sub Create_PDFs()
Dim dataValidationCell As Range, dataValidationListSource As Range, dvValueCell As Range
Dim dropdownValue As String
Dim PDFfile As String, i As Long
Dim destinationFolder As String
destinationFolder = ThisWorkbook.Path
'destinationFolder = "C:\path\to\folder" 'Or specific folder
If Right(destinationFolder, 1) <> "" Then destinationFolder = destinationFolder & ""
'Cell containing data validation in-cell dropdown
Set dataValidationCell = Worksheets("Summary_Page").Range("g4")
'Source of data validation list
Set dataValidationListSource = Evaluate(dataValidationCell.Validation.Formula1)
'Create PDF for each data validation value
For Each dvValueCell In dataValidationListSource
dataValidationCell.Value = dvValueCell.Value
With dataValidationCell.Worksheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=destinationFolder & dvValueCell.Value & ".PDF", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Next
End Sub