Monday, 15 February 2010

excel - Reverse order of For Each loop -



excel - Reverse order of For Each loop -

one of powerful things vb ability loop through objects in collection without referring index - for each loop.

i find useful want remove objects collection.

when doing removing objects predefined such rows on spread sheet code simpler if utilize indexing , start @ largest , work first. (step -1 iterator) (otherwise requires offset each moves enumerator pointer previous object 1 time active 1 deleted)

eg.

for inta = 10 1 step -1 ' ... next

what when using each | next eg.

for each rngcell in selection.cells ' ... next

how loop backwards using for each loop syntax?

for built in collections (eg range) short reply is: can't. user defined collections reply linked @vblades might useful, although cost might outweigh benifit.

one work around seperate identification of items removed actual removal. eg, range, build new range variable using union, process variable, eg delete rows in 1 go. range example, can take advantage of variant array method farther speed things up.

whether or not of useful depend on actual utilize case.

excel vba excel-vba foreach

No comments:

Post a Comment