Delete Cells when error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

what am I doing wrong here? I need to delete cells D & E if there is an
error in D.

With Sheets("Table")
LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row

For iCtr = LrowinD To FrowinD Step -1
With .Cells(LrowinD, "D")
If IsError(.Value) Then
.Cells(LrowinD, "D:E").Select
Selection.Delete Shift:=xlUp
End If
End With
Next
End With

Thanks for yor help.
 
Karen,

Try,

Sub marine()
FrowinD = 1
With Sheets("Table")
LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row
For ictr = LrowinD To FrowinD Step -1
If IsError(Cells(ictr, 4).Value) Then
Range("D" & ictr & ":E" & ictr).Select
Selection.Delete Shift:=xlUp
End If
Next
End With
End Sub

Mike
 
Yea!!! Thank you Mike!

Mike H said:
Karen,

Try,

Sub marine()
FrowinD = 1
With Sheets("Table")
LrowinD = .Cells(.Rows.Count, "D").End(xlUp).Row
For ictr = LrowinD To FrowinD Step -1
If IsError(Cells(ictr, 4).Value) Then
Range("D" & ictr & ":E" & ictr).Select
Selection.Delete Shift:=xlUp
End If
Next
End With
End Sub

Mike
 
Mike has provided a nice solution. However, I would recommend
removing the select line. It is good coding practice to not select
anything if not absolutely necessary.
You could replace this:
If IsError(Cells(ictr, 4).Value) Then
Range("D" & ictr & ":E" & ictr).Select
Selection.Delete Shift:=xlUp
End If

With this:
If IsError(Cells(ictr, 4).Value) Then _
Range("D" & ictr & ":E" & ictr).Delete Shift:=xlUp
 

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

Back
Top