Reverse order of For Each loop

前端 未结 5 1448
一整个雨季
一整个雨季 2020-12-01 17:40

One of the most powerful things about VB is ability to loop through objects in a collection WITHOUT referring to the index - for each loop.

I find it ve

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 18:18

    For built in collections (eg a Range) the short answer is: you can't. For user defined collections the answer linked by @VBlades might be useful, although the cost might outweigh the benifit.

    One work around is to seperate the identification of items to be removed from the actual removal. Eg, for a range, build up a new range variable using Union, then process that variable, eg delete all the rows in one go. For the Range example, you can also take advantage of the Variant Array method to further speed things up.

    Whether or not any of this is useful will depend on your actual use case.

提交回复
热议问题