Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default for next loop not working


Help!
I have a For/Next loop that is working fine for the first 13 of 14 items
(NumOfEndItems = 14 in this case), then instead of going to item 14, it skips
from 13 to 175 and exits the loop prematurely, before item 14 can be
processed... has anyone run into this or a similar problem before?

For T = 1 To NumOfEndItems
Call GetDaBOM(EndItem(T), AllBOMsPage, T)
Next

Could it be that GetDaBOM is returning something it shouldn't or maybe a
problem with variables being defined globally/locally?

Confused,
Dante

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default for next loop not working


Something is modifying the value of 'T' outside of your For Next routine.
You could try changing your GetDaBOM function declaration to pass the
argumanets ByVal instead of ByRef, ie:-

Public Function GetDaBOM(ByVal ThisEndItem as Object, ByVal ThisAllBOMsPage
as Object, ByVal ThisT As Object) As Long

'T' could be public scoped as you say, but I guess you must have checked
this already.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"dantee" wrote:

Help!
I have a For/Next loop that is working fine for the first 13 of 14 items
(NumOfEndItems = 14 in this case), then instead of going to item 14, it skips
from 13 to 175 and exits the loop prematurely, before item 14 can be
processed... has anyone run into this or a similar problem before?

For T = 1 To NumOfEndItems
Call GetDaBOM(EndItem(T), AllBOMsPage, T)
Next

Could it be that GetDaBOM is returning something it shouldn't or maybe a
problem with variables being defined globally/locally?

Confused,
Dante

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default for next loop not working

Ok. I made a dumb mistake. Sorry about that.
There is an "if" statement within the subroutine GetDaBOM that modified T in
certain cases: i used the variable T within that conditional statement (and
within the subroutine) to count something else besides EndItem(T) by
accident. It was careless on my part.

It really does help to bounce these problems off other vba users. Careless
mistake or not. Thanks for extending your help.

Dante
--

"Alan Moseley" wrote:

Something is modifying the value of 'T' outside of your For Next routine.
You could try changing your GetDaBOM function declaration to pass the
argumanets ByVal instead of ByRef, ie:-

Public Function GetDaBOM(ByVal ThisEndItem as Object, ByVal ThisAllBOMsPage
as Object, ByVal ThisT As Object) As Long

'T' could be public scoped as you say, but I guess you must have checked
this already.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"dantee" wrote:

Help!
I have a For/Next loop that is working fine for the first 13 of 14 items
(NumOfEndItems = 14 in this case), then instead of going to item 14, it skips
from 13 to 175 and exits the loop prematurely, before item 14 can be
processed... has anyone run into this or a similar problem before?

For T = 1 To NumOfEndItems
Call GetDaBOM(EndItem(T), AllBOMsPage, T)
Next

Could it be that GetDaBOM is returning something it shouldn't or maybe a
problem with variables being defined globally/locally?

Confused,
Dante

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...Each loop not working Jayne22 Excel Programming 5 August 13th 08 03:22 PM
Do Until Loop Not Working PJFry Excel Programming 1 October 1st 07 07:20 PM
Loop Not Working Paul Black Excel Programming 7 August 29th 07 08:33 PM
for next loop not working Tom Ogilvy Excel Programming 0 September 27th 04 05:36 PM
for next loop not working Ron Rosenfeld Excel Programming 0 September 25th 04 04:07 AM


All times are GMT +1. The time now is 05:24 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"