PC Review


Reply
Thread Tools Rate Thread

Deleting rows when cell has "#DIV/0!" error

 
 
mattg
Guest
Posts: n/a
 
      19th Apr 2010
Hi,

I'm currently using this code to delete rows with balnk cells. However, i
have changes the formatting of my sheet and the cells are no longer blank
they have the "#DIV/0!" error. How can I delete the entire row when the cell
in column D has that value?

Sub DeleteRowsIfDIsBlank()

With payrollsht

Dim rg As Range, rgBlank As Range

Set rg = Cells.Range("D")

On Error Resume Next

Set rgBlank = rg.SpecialCells(xlCellTypeBlanks)

On Error GoTo 0

If rgBlank Is Nothing Then

Else

rgBlank.EntireRow.Delete

End If

End With

End Sub

 
Reply With Quote
 
 
 
 
Wouter HM
Guest
Posts: n/a
 
      19th Apr 2010
Hi matt,

In Excel 2003 I creates this:

Sub DeleteRowsIfDIsError()

Dim i As Integer
With ActiveSheet
' start with last used row
For i = Cells(65536, 4).End(xlUp).Row _
To 1 Step -1
If IsError(Cells(i, 4).Value) Then
Rows(i).EntireRow.Delete
End If
Next
End With
End Sub

HTH,

Wouter
 
Reply With Quote
 
Project Mangler
Guest
Posts: n/a
 
      19th Apr 2010
Hi Mattg,

If #DIV/0! is the only error in Column D you could try a loop with

Set rgError = rg.SpecialCells(xlCellTypeFormulas, xlErrors)

or something like that (bearing in mind the limitations of Specialcells)

HTH

"mattg" <(E-Mail Removed)> wrote in message
news:3888F1D6-21BB-4230-BDA7-(E-Mail Removed)...
> Hi,
>
> I'm currently using this code to delete rows with balnk cells. However, i
> have changes the formatting of my sheet and the cells are no longer blank
> they have the "#DIV/0!" error. How can I delete the entire row when the

cell
> in column D has that value?
>
> Sub DeleteRowsIfDIsBlank()
>
> With payrollsht
>
> Dim rg As Range, rgBlank As Range
>
> Set rg = Cells.Range("D")
>
> On Error Resume Next
>
> Set rgBlank = rg.SpecialCells(xlCellTypeBlanks)
>
> On Error GoTo 0
>
> If rgBlank Is Nothing Then
>
> Else
>
> rgBlank.EntireRow.Delete
>
> End If
>
> End With
>
> End Sub
>



 
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
Deleting rows when cell text reads "Research" iashorty Microsoft Excel Programming 2 7th Nov 2008 07:07 PM
delete rows if cell in row contains "a" or "o" or empty bartman1980 Microsoft Excel Programming 2 4th Nov 2007 08:20 PM
Look for cell containing "Initial" then if the next cell after equals "Final" then delete both rows. amorrison2006@googlemail.com Microsoft Excel Programming 3 28th Sep 2007 01:45 PM
Deleting groups of continuous rows where col K = "x" Max Microsoft Excel Programming 6 18th Feb 2006 11:21 PM
Resetting "End" "Home" After Deleting Rows =?Utf-8?B?RG91Zw==?= Microsoft Excel Worksheet Functions 1 24th Mar 2004 10:06 PM


Features
 

Advertising
 

Newsgroups
 


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