for next loop not working

D

dantee

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
 
A

Alan Moseley

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.
 
D

dantee

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
--
 

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