deleting rows, endless loop maybe ?

  • Thread starter Thread starter dick
  • Start date Start date
D

dick

Perhaps this is a dumb Q, but a brief experiment looking at ranges in
Immediate Window causes me to ask this question. Will the following
(with correct syntax) cause an endless loop since the cells shifting
into the range will be empty?

range = a1:a10 (for example)
for each empty cell in range, delete the row

a11, a12, etc are in fact empty.

Thanks!
 
No, it will cause you to miss some cells. for example, if rows 2, 3 and 4
are emty, it will delete 2 and 4 and miss 3.

Usually one loops from higher to lower

for i = 10 to 1 step -2
if isempty(cells(i,1)) then
rows(i).Delete
End if
Next
 
It should be step -1. Sorry. Guess I had 2 still on the mind from the
exciting explantion I gave <g>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top