How to fix cell.entirerow.delete?

G

guy

I am checking cells in a column for a value and when found I do cell.entirerow.delete but my for
each loop must be messing up because some rows are skipped. How done?

for each mycell in myrange
if mycell.value = "delete" then
mycell.entirerow.delete
end if
next
 
R

Robin Hammond

Guy,

you are messing up the range definition with each delete. You need to work
down from the end of the range. e.g.

lRows = MyRange.Rows.Count
For lCounter = lRows to 1 Step -1
if MyRange(lCounter,1).Value = "delete" Then _
MyRange(lCounter,1).EntireRow.Delete
Next lCounter

Robin Hammond
www.enhanceddatasystems.com
 

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

Top