Handling a Null Cell in Macro

K

Ken

The following loop is part of a larger macro.

For ILoop = NumRowsF850 To 1 Step -1
If Cells(ILoop, 5) = 0 Then
Rows(ILoop).Delete
End If
Next ILoop

If I find a null cell in the loop on line two, it is evaluated as 0 and the
code branches to the third line.

I do not want to execute the third line of code if the cell is null.

How do I need to re-code line two to avoid this problem?

TIA.
 
P

Phil Webb

Try adding a check for isempty:

For iloop = numrowsf850 To 1 Step -1
If Cells(iloop, 5) = 0 And Not IsEmpty(Cells(iloop, 5)) Then
Rows(iloop).Delete
End If
Next iloop

Regards,
Phil Webb
 

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