Reversing the order of a For-Each loop action?
There is no way to change the order of a for each. What you can do is to
create one big range to delete instead of deleting one row at a time. It is a
bit more code but it runs a fair bit faster...
dim rng as range
dim rngToDelete as range
for each rng in sheets("MySheet").range("MyRange")
if rng.value = "Something" then
if rngtodelete is nothing then
set rngtodelete = rng
else
set rngtodelete = union(rng, rngtodelete)
end if
end if
next rng
if not rngtodelete is nothing then rngtodelete.entirerow.delete
--
HTH...
Jim Thomlinson
"Henry" wrote:
To all you knowledgeable and helpful people,
I'm using a For-Each loop to run through a named Range and delete all
non-blank Rows. This only removes alternate Rows. I know it should be done
from the bottom of the Range upwards. Is it possible to get a For-Each loop
to start at the bottom of the Range and work upwards? I know how to do it in
a For-Next loop, but Step -1 obviously won't work if the loop counter is
pointing at the top Row to start with! The size of the Range, on entering
the loop, is indeterminate.
TIA
Henry
|