Print Multiple Sheets Dynamically based on Userform Listbox Selections

brenner

Board Regular
Joined
Sep 13, 2007
Messages
96
I'm trying to pass an array of sheet names through the printout method, but keep receiving a fatal error that crashes excel. I have verified that each sheet exist in the active workbook. Additionally, if I replace the variable PrintArray with the values ("GG","N3","Z.2"), the code will run.

Any thoughts are greatly appreciated.


Error Message:
"Automation error
Exception occurred."

Line where code errors:
Sheets(Array(PrintArray).PrintOut

Array Values when code errors:
PrintArray(0) = "GG"
PrintArray(1) = "N3"
PrintArray(2) = "Z.2"
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
i hope so u can use the FOR loop to print sheets or print odd number sheets or print all sheets from 2 sheet just amend the code

'the below is to print all sheets
for i = 1 to sheets.count
sheets(i).print
next

'the below is to print from 3 sheets
for i = 3 to sheets.count
sheets(i).print
next
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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