first time array help

G

Guest

trying to use array to define 9 sheets tabs for sheets Nbr 1-9
cannot get pass following.
Dim ws As Worksheets
For Each ws In ThisWorkbook.Worksheets(Array("sheet1", "sheet2", "sheet3",
"sheet4", "sheet5", "sheet6", "sheet7", "sheet8", "sheet9"))
for each yellows out
code here for print area and nbr copies
is it to many sheets does array have limits
build these sheets then want to print out of all at same time.
 
G

Guest

Curt,

here is a way to create 9 sheets

Sub Curt()
Dim i As Long
For i = 1 To 9
Sheets.Add
ActiveSheet.Name = "Nbr" & i
Next i
End Sub


Here is a way to print the array
Sheets (Array ("Nbr1", "Nbr2", "Nbr3", "Nbr4", "Nbr5", "Nbr6", "Nbr7",
"Nbr8" ,"Nbr9" )).Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
 
G

Gary Keramidas

maybe something like this:
Sub test()
Dim shArray As Variant
Dim i As Variant
shArray = Array("sheet1", "sheet2", "sheet3", _
"sheet4", "sheet5", "sheet6", "sheet7", "sheet8", "sheet9")
For Each i In shArray
Worksheets(i).Activate
Next
End Sub
 
D

Dave Peterson

If your sheets are all named nicely, you could rely on that, too:

dim wCtr as long
for wctr = 1 to 9
with worksheets("sheet" & wctr)
'code to do your print area and number of copies
'and print each sheet one at a time.
end with
next wctr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top