odd issue with a loop

J

Joseph Atie

For counter = 1 To scount
sstring = Cells(counter + 82, 2).Value
Sheets(sstring).Select
ActiveSheet.PageSetup.Zoom = 75
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next counter

the above section of code works for the first iteration of the loop on the
second iteration it fails to give sstring a value.

is there something wrong with the code?

p.s the aim of the code is to print off a number of sheets
 
N

Nigel

You need to specify the value of scount before the loop, also the line

Cells(Counter + 82, 2).Value

Is not fully referenced, so as you change the sheet, you are referencing the
Activesheet with the above statement, that maybe what you want ? If not add
the name of the sheet with the data e.g.

Sheets("Table").Cells(Counter + 82, 2).Value
 
D

Dave Peterson

Just to add to Nigel's response:

It's better to qualify the ranges and not select the sheet:

For counter = 1 To scount
sstring = worksheets("table").Cells(counter + 82, 2).Value
with Sheets(sstring)
.PageSetup.Zoom = 75
.PrintOut Copies:=1, Collate:=True
end with
Next counter
 

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