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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variable to iterate through rows

Status
Not open for further replies.

westicle47

Programmer
May 24, 2004
20
GB
I often use the following code to move through rows on a spreadsheet, executing some other code at each row, and was wondering if there is a more simple or established way of performing this (not that it's that complicated).

Employee_Row = Employee_Row + 1
Cells(Employee_Row, 1).blah blah blah
Next blah

I vaguely remember in an introductory course on Java that you can use something like Employee_Row++ to perform the same function.

Thanks

Westie
 
I know. My question was "is there an equivalent function in VBA or just a better way of performing the same action?
 
you are using For Each loops, this is fundamentally the way forward.
in your case you are using a incremented integer. is there a shortenned way to increment an integer in vba/s...no i would say not

how to dispense with the incremented integer?
use collections and iterate through them using For Each
 
Thanks mrmovie. I wanted to make sure I wasn't missing something really obvious.

I have tried using collections and For Each loops but I struggle with them. I can eventually get them to work after lots of trial and error but it's the theory and programming conventions behind them that I don't quite get. Perhaps I'll give it a go and post up my probs when they arrive.
 
yeah i get what you mean, i never tend to use cell collections in excel cause i think it relies on returning ranges...my problem is i dont know how to manipulate/create ranges...hence i go for the old fashioned approach as you have outlined...works for me though and i would say almost makes you code more portable if you wanted move the data out of excel and into a database for instance??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top