Sub DeleteRow_If_Cell_NotEmpty()
Dim iLastRow As Long
Dim iCol As Long
Dim i As Long
iCol = ActiveCell.Column
With ActiveSheet
iLastRow = .Cells(.Rows.Count, iCol).End(xlUp).Row
For i = iLastRow To ActiveCell.Row Step -1
If .Cells(i, iCol - 1).Value < 0 Then
If .Cells(i, iCol).Value < "" Then
.Rows(i).Delete
End If
Else
Exit Sub
End If
Next i
End With
End Sub
--
HTH
Bob Phillips
(there's no email, no snail mail, but somewhere should be gmail in my addy)
"PE" wrote in message
...
I am trying to write a macro which would:
1) check the cell to the left - if value is 0 (or cell is empty) then
macro
is abandoned else......
2) if current cell is non-empty then the row is deleted and back to 1) to
check the next row
3) if current cell is empty then move down 1 cell and back to 1)
I have tried the following:
Sub DeleteRow_If_Cell_NotEmpty()
Do
If ActiveCell.Offset(0, -1).Value 0 Then
If ActiveCell < "" Then
Selection.EntireRow.Delete
Else 'go to next row
ActiveCell.Offset(1, 0).Select
End If
Else
Exit Sub
End If
Loop
End Sub
If I step into the macro using F8 in VB editor it works fine. But when I
use the macro normally I get the error "Code execution has been
interrupted"
and on clicking the debug button the first End If above is highlighted.
Would appreciate your help.
Al