PC Review


Reply
Thread Tools Rate Thread

Delete Cells when error

 
 
=?Utf-8?B?S2FyZW41Mw==?=
Guest
Posts: n/a
 
      12th Sep 2007
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      12th Sep 2007
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

"Karen53" wrote:

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

 
Reply With Quote
 
=?Utf-8?B?S2FyZW41Mw==?=
Guest
Posts: n/a
 
      12th Sep 2007
Yea!!! Thank you Mike!

"Mike H" wrote:

> 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
>
> "Karen53" wrote:
>
> > 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.

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      12th Sep 2007
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

Karen53 wrote:
> Yea!!! Thank you Mike!
>
> "Mike H" wrote:
>
> > 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
> >
> > "Karen53" wrote:
> >
> > > 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
delete cells column. Delete empty cells myshak Microsoft Excel Worksheet Functions 0 9th Mar 2009 10:59 PM
Cannot delete spreadsheet cells ERROR Nikki Microsoft Access External Data 0 24th Sep 2008 09:05 PM
delete error/blank cells Ask MS Microsoft Excel Worksheet Functions 3 30th Jun 2008 01:54 PM
Error Msg: Cannot Delete Spreadsheet Cells =?Utf-8?B?U3RldmVu?= Microsoft Access VBA Modules 0 7th Mar 2007 10:46 PM
macro to select cells containing specific text and delete all cells but these JenIT Microsoft Excel Programming 3 27th Mar 2006 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.