Handling a Null Cell in Macro  
Author Message
RickeyDharna





PostPosted: Tue Oct 19 19:51:15 CDT 2004 Top

Excel Programming >> Handling a Null Cell in Macro

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.

Excel344  
 
 
Phil





PostPosted: Tue Oct 19 19:51:15 CDT 2004 Top

Excel Programming >> Handling a Null Cell in Macro 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




> 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.
>