VBA optimization with a "For Each"
I want to check rows 50,000 and greater for some cell background color on a 60,000 row sheet. Right now I essentially goNow it actually spins for a couple of seconds just getting up to line 50000. I'd like to improve that. I already see thatPlease Login or Register to view this content.
dim wksht as worksheet
and substituting wksht for Worksheets(i) is useful, since my belief is that the "high bound" of the For statement is reevaluated every single time.
I could also put "With c" above the if statement, but the goal here is to speed the
For Each
If
end if
next
construct so a "With" there would seem to actually slow the interpretive processor. (Side note: I'm not clear whether snail-paced VBA is actually "compiled." I suspect that the "debug/compile" option really is nothing but a syntax preprocessor. Elucidation welcome.)
An obvious possibility is to instead of wksht.UsedRange define a range of the specified row, column A, to the end of the worksheet. I'm not sure how I'd code that; for one thing, it may not be on the active sheet, so ActiveCell.SpecialCells(xlLastCell) or ActiveCell.SpecialCells(xlLastCell).Row doesn't work per se. I'm interested in how it would be coded, yet note that iStartRow may be row 1 in some cases, not necessarily 50000. Any solution would need to be to optimize both situations.
TIA for advice.
Bookmarks