Excel VBA overlapping error for deleting highlighted rows -


i'm trying understand why error pops when didn't before

sub deleterow()    dim cell range, delrange range     each cell in activesheet.range("a2:g2000")        if cell.interior.colorindex = 6            if delrange nothing                set delrange = cell            else                set delrange = union(delrange, cell)            end if        end if     next cell     if not delrange nothing delrange.entirerow.delete ' error here end sub 

this part of recorded vba macro deleting highlighted rows it's showing error run time error "1004" - "cannot use command on overlapping selection" in line delrange.entirerow.delete.

it didn't occur before.

thanks in advance

sub deleterow() dim cell range  application.screenupdating = false  each cell in activesheet.range("a2:g2000")     cell         if .interior.colorindex = 6 .entirerow.delete     end next cell  application.screenupdating = true  end sub 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -