ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   odd issue with a loop (https://www.excelbanter.com/excel-programming/423937-odd-issue-loop.html)

Joseph Atie

odd issue with a loop
 
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

Leith Ross[_755_]

odd issue with a loop
 

Joseph Atie;226536 Wrote:
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


Hello Joseph,

Since the loop only runs once, that indicates the control value sCount
is less than 1. You need to make sure the variable is initialized
before startingg the loop.


--
Leith Ross

Sincerely,
Leith Ross

'The Code Cage' (http://www.thecodecage.com/)
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=62924


Nigel[_2_]

odd issue with a loop
 
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

--

Regards,
Nigel




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



Dave Peterson

odd issue with a loop
 
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

Nigel wrote:

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

--

Regards,
Nigel


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


--

Dave Peterson

Joseph Atie

odd issue with a loop
 
thats what im missing, thanks heaps

i knew it would be something simple

Joseph

"Nigel" wrote:

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

--

Regards,
Nigel




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





All times are GMT +1. The time now is 08:48 AM.

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