findingcindy
New Member
- Joined
- Apr 3, 2025
- Messages
- 7
- Office Version
- 2013
- Platform
- Windows
I have the following code that loops through a list of 150+ store numbers on "Lookup Data" tab, changes b4 cell on the "Scorecard" tab to the store number to populate the current data for that store, then exports the "Scorecard" tab plus the chart tab (which auto-populates to that store number) to a PDF with the store number as the file name. I keep getting a Compile Error : Invalid outside procedure. The export function works properly and the looping function works properly but when I put them together, I get that error. Thank you for any help you can offer. I've been struggling with this for hours.
End Sub
VBA Code:
Dim i As Long, LastRow As Long
Dim SaveLocation As String
Dim rng As Range
SaveLocation = "C:\Users\cindy\OneDrive\Desktop\Consulting"
Set rng = Worksheets("Scorecard").Range("A1: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:=True
End If
Next i
End Sub