Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For ..Next Problem 1

Status
Not open for further replies.

philcon

Technical User
Feb 5, 2002
139
GB
A no-brainer I'm sure but could anyone possibly tell me why this for next loop appears to be getting ignored

For TransCounter = (TransCount + 1) To 0
TransArr(Colnum, TransCounter) = TransArr(Colnum, TransCounter - 1)
Debug.Print TransArr(Colnum, TransCounter)
Next TransCounter

Transcount currently equals 1 so there should be two iterations, however when I use step through in debug, the process just jumps through the loop from the For Statement to the next line of code after the Next Statement

Hope you can help.

regards


Phil.
 
The reason it is jumping through it is because you first instance of Transcounter = 2 which is already greater than 0 so it will not jump into the loop. If you wanted to count down you need to do something like this:

For TransCounter = TransCount To 0 Step -1

And you really don't want to do any math functions within the For statement(ie TransCount + 1). This may give you some unexpected results.

Well good luck,
Shane
 
Thanks for that, knew it was a no-brainer,also will bear in mind the tip re math functions.

Thanks again

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top