ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   first time array help (https://www.excelbanter.com/excel-programming/398561-first-time-array-help.html)

Curt

first time array help
 
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.


JRForm

first time array help
 
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


"Curt" wrote:

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.


Gary Keramidas

first time array help
 
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

--


Gary


"Curt" wrote in message
...
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.




Dave Peterson

first time array help
 
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

Curt wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com