Hi,
I am trying to use the following code, but I keep getting the "Subscript Out of Range" error.
I'm sure it has to do with the my variable:
The code basically looks in each worksheet to see if there is data in it and if there is, I want to print that to PDF.
When I hardcode in the following into the Sheets(Array(...)).Select line, it works:
so I can only assume that the problem is with my ArrSheets variable...any ideas as to why this doesn't work?
If you need anymore info, please let me know.
Thanks,
Eoin
I am trying to use the following code, but I keep getting the "Subscript Out of Range" error.
I'm sure it has to do with the my variable:
The code basically looks in each worksheet to see if there is data in it and if there is, I want to print that to PDF.
Code:
Dim ArrSheets As String
ArrSheets = Chr(34) & "Cover" & Chr(34)
For i = 3 To 7
If Worksheets(i).Range("F4").Value <> "" Then
ArrSheets = ArrSheets & ", " & Chr(34) & Worksheets(i).Name & Chr(34)
End If
Next i
If Worksheets(9).Range("D6").Value <> "" Then
ArrSheets = ArrSheets & ", " & Chr(34) & Worksheets(9).Name & Chr(34)
End If
Sheets(Array(ArrSheets)).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"C:\Data\FileOutput.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
When I hardcode in the following into the Sheets(Array(...)).Select line, it works:
Code:
Sheets(Array("Cover", "Region 1", "Region 2", "Region 3", "Other")).Select
so I can only assume that the problem is with my ArrSheets variable...any ideas as to why this doesn't work?
If you need anymore info, please let me know.
Thanks,
Eoin