Another VBA issue

findingcindy

New Member
Joined
Apr 3, 2025
Messages
7
Office Version
  1. 2013
Platform
  1. 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
 
Hello @findingcindy. Maybe like
VBA Code:
        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")).Copy

            With ActiveWorkbook
                .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                        SaveLocation & Worksheets("Scorecard").Range("B4").Value, Quality:= _
                        xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
                        OpenAfterPublish:=False
                .Close SaveChanges:=False
            End With

        End If
 
Upvote 0
Solution
Hello @findingcindy. Maybe like
VBA Code:
        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")).Copy

            With ActiveWorkbook
                .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                        SaveLocation & Worksheets("Scorecard").Range("B4").Value, Quality:= _
                        xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
                        OpenAfterPublish:=False
                .Close SaveChanges:=False
            End With

        End If
Thank you so much !!! That worked perfectly!
 
Upvote 0

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