I would like to select multiple worksheet depending on the userform checkboxes status and I am receiving error at the selection. I have a total of 16 checkboxes in my userform, so I need a method to determine the sheets to be selected.
Short Example:
`Sub chkboxes()'
DIM SheetNames as string
If CB1.value = true then
SheetNames = "SummaryReport"
End IF
If CB2.value = true and sheetNames <> "" then
SheetNames = Sheetnames & "," & "WeekdaysReport"
elseif CB2.value = true and sheetnames = "" then
SheetNames = "WeekdaysReport"
End If
If CB3.value = true and sheetnames <> "" then
SheetNames = SheetNames & "," & "WeekendsReport"
elseif CB3.value = true and SheetNames <> "" then
SheetNames = "WeekendsReport"
End If
If SheetNames = ""
Exit Sub
End If
Sheets(Array(SheetNames)).select **'This is where the script stops and prompt error.**
Call ExportToPDF
SheetNames = ""
End Sub
The above is pretty amateur, I am still very unfamiliar with vba and programming. Hopefully i could get some guidance. Thanks.
I have tried searching for solution online, but failed to find similar post.
There is unnecessary call of “Array” function in your code and few other “shortcuts”.
Please replace following lines:
with this snippet:
And, I hope, now procedure should works if my assumptions was right.
Ups, I have found another issue…
If I’m correctly guessing your intensions, the resposible code for each CheckBox should looks like this: