findingcindy
New Member
- Joined
- Apr 3, 2025
- Messages
- 7
- Office Version
- 2013
- Platform
- Windows
Good morning! I've gotten help with this code once and I've been struggling with the second part of it all morning. Everything is working except when the pdf is created (it goes to the right folder, the code deletes everything in the folder first, as I wanted) but it is selecting Scorecard and Chart sheets but then also adds in the tracker tab, which I do not want it to add. I have no idea why it is doing that and it is driving me crazy. Ideas?
VBA Code:
Sub Scorecards()
Dim i As Long, LastRow As Long
Dim SaveLocation As String
Dim rng As Range
Dim myFilePath As String
myFilePath = "C:\Users\cindy\OneDrive\Desktop\Consulting\Test\*.*"
If Dir(myFilePath) <> "" Then
Kill myFilePath
End If
SaveLocation = "C:\Users\cindy\OneDrive\Desktop\Consulting\Test\"
Set rng = Worksheets("Scorecard").Range("A2:H43")
LastRow = Worksheets("Lookup Tables").Range("A500").End(xlUp).Row
For i = 1 To LastRow
If Not Worksheets("Lookup Tables").Range("A" & i).Value = 0 Then
Worksheets("Scorecard").Range("b4").Value = Worksheets("Lookup Tables").Range("A" & i).Value
Sheets(Array("Scorecard", "Chart")).Select
Sheets("Scorecard").Activate
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
SaveLocation & Range("b4").Value, Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
openafterpublish:=False
End If
Next i
End Sub