Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
For next do loop issue Christian Falde Excel Discussion (Misc queries) 4 November 11th 08 07:01 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
do ... until loop issue pjjclark Excel Programming 4 November 29th 05 04:24 PM
Issue with Do Loop Linking to specific cells in pivot table Excel Programming 3 July 24th 05 10:38 PM


All times are GMT +1. The time now is 03:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"