PC Review


Reply
Thread Tools Rate Thread

Delete rows based on more than one condition.

 
 
thomas
Guest
Posts: n/a
 
      23rd Sep 2008
I have tried the other answers without success because my grasp of vba is
just too weak.

I want to delete all rows if their respective cells in column "G" contains
either a value of less than 0.5 or "#VALUE!". My data range is from "A" to
"H" with variable number of variable rows and starting from row "3".


I appreciate a helping hand. Thank you.


 
Reply With Quote
 
 
 
 
sbitaxi@gmail.com
Guest
Posts: n/a
 
      23rd Sep 2008
On Sep 23, 9:05*am, thomas <tho...@discussions.microsoft.com> wrote:
> I have tried the other answers without success because my grasp of vba is
> just too weak.
>
> I want to delete all rows if their respective cells in column "G" contains
> either a value of less than 0.5 or "#VALUE!". My data range is from "A" to
> "H" with variable number of variable rows and starting from row "3".
>
> I appreciate a helping hand. Thank you.


Hello Thomas,

Give this a try. Untested. I'm not sure if the Error.Type will capture
the #Value, but if not someone here will definitely be able to tweak
this. It should select the range you want to delete, until you are
ready to delete.

Steven

Sub DelRows()
Dim Rng As Range
Dim DelRng As Range
Dim LRow As Long

LRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

Set Rng = Range("A3:H" & LRow)
Rng.AutoFilter Field:=Thing, Criteria1:="=0.5", _
Operator:=xlOr, Criteria2:="=" & Error.Type(3)

Set DelRng = Union(IIf(Rng Is Nothing,
SrcRng.Cells.SpecialCells(xlVisible), Rng), _
SrcRng.Cells.SpecialCells(xlVisible))
ActiveSheet.AutoFilterMode = False

If Not DelRng Is Nothing Then DelRng.EntireRow.Select
'change to Delete
Set DelRng = Nothing

End Sub
 
Reply With Quote
 
thomas
Guest
Posts: n/a
 
      24th Sep 2008
Steven,

When I tried your code, I got runtime error '424' Object required.


Thomas



"(E-Mail Removed)" wrote:

> On Sep 23, 9:05 am, thomas <tho...@discussions.microsoft.com> wrote:
> > I have tried the other answers without success because my grasp of vba is
> > just too weak.
> >
> > I want to delete all rows if their respective cells in column "G" contains
> > either a value of less than 0.5 or "#VALUE!". My data range is from "A" to
> > "H" with variable number of variable rows and starting from row "3".
> >
> > I appreciate a helping hand. Thank you.

>
> Hello Thomas,
>
> Give this a try. Untested. I'm not sure if the Error.Type will capture
> the #Value, but if not someone here will definitely be able to tweak
> this. It should select the range you want to delete, until you are
> ready to delete.
>
> Steven
>
> Sub DelRows()
> Dim Rng As Range
> Dim DelRng As Range
> Dim LRow As Long
>
> LRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
>
> Set Rng = Range("A3:H" & LRow)
> Rng.AutoFilter Field:=Thing, Criteria1:="=0.5", _
> Operator:=xlOr, Criteria2:="=" & Error.Type(3)
>
> Set DelRng = Union(IIf(Rng Is Nothing,
> SrcRng.Cells.SpecialCells(xlVisible), Rng), _
> SrcRng.Cells.SpecialCells(xlVisible))
> ActiveSheet.AutoFilterMode = False
>
> If Not DelRng Is Nothing Then DelRng.EntireRow.Select
> 'change to Delete
> Set DelRng = Nothing
>
> End Sub
>

 
Reply With Quote
 
sbitaxi@gmail.com
Guest
Posts: n/a
 
      24th Sep 2008
On Sep 23, 8:59*pm, thomas <tho...@discussions.microsoft.com> wrote:
> Steven,
>
> When I tried your code, I got runtime error '424' Object required.
>
> Thomas
>
> "sbit...@gmail.com" wrote:
> > On Sep 23, 9:05 am, thomas <tho...@discussions.microsoft.com> wrote:
> > > I have tried the other answers without success because my grasp of vba is
> > > just too weak.

>
> > > I want to delete all rows if their respective cells in column "G" contains
> > > either a value of less than 0.5 or "#VALUE!". My data range is from "A" to
> > > "H" with variable number of variable rows and starting from row "3".

>
> > > I appreciate a helping hand. Thank you.

>
> > Hello Thomas,

>
> > Give this a try. Untested. I'm not sure if the Error.Type will capture
> > the #Value, but if not someone here will definitely be able to tweak
> > this. It should select the range you want to delete, until you are
> > ready to delete.

>
> > Steven

>
> > Sub DelRows()
> > Dim Rng As Range
> > Dim DelRng As Range
> > Dim LRow As Long

>
> > LRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

>
> > Set Rng = Range("A3:H" & LRow)
> > * * * * Rng.AutoFilter Field:=Thing, Criteria1:="=0.5", _
> > * * * * * * * * * * * * Operator:=xlOr, Criteria2:="=" & Error.Type(3)

>
> > Set DelRng = Union(IIf(Rng Is Nothing,
> > SrcRng.Cells.SpecialCells(xlVisible), Rng), _
> > * * * * * * SrcRng.Cells.SpecialCells(xlVisible))
> > * * * * * * ActiveSheet.AutoFilterMode = False

>
> > * * * * * * If Not DelRng Is Nothing Then DelRng.EntireRow.Select
> > 'change to Delete
> > * * * * * * Set DelRng = Nothing

>
> > End Sub


Revised - Sorry, I rushed and didn't change a couple of variables I
had used in the other code.

S

Sub DelRows()
Dim Rng As Range
Dim DelRng As Range
Dim LRow As Long

LRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
LRow = 20
Set Rng = Range("A3:H" & LRow)
Rng.AutoFilter Field:=5, Criteria1:="=0.5", _
Operator:=xlOr, Criteria2:="=#VALUE!"

Set DelRng = Union(IIf(DelRng Is Nothing,
Rng.Cells.SpecialCells(xlVisible), DelRng), _

Rng.Cells.SpecialCells(xlVisible))
ActiveSheet.AutoFilterMode = False

If Not DelRng Is Nothing Then DelRng.EntireRow.Select
'change to delete
Set DelRng = Nothing

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
Want to delete rows based on a condition marcia2026 Microsoft Excel Programming 9 31st Oct 2009 10:54 AM
Delete Rows based on condition Vic Microsoft Excel Misc 2 18th Aug 2009 08:54 PM
hide multiple rows based on condition within rows =?Utf-8?B?U2t5bWFubg==?= Microsoft Excel Programming 6 21st Oct 2007 04:01 PM
Macro to delete rows based on a condition =?Utf-8?B?RGFycmlseW4=?= Microsoft Excel Worksheet Functions 1 6th Sep 2007 12:12 AM
Hide rows based on a condition =?Utf-8?B?S2ltYmVybHlI?= Microsoft Excel Programming 2 29th Mar 2006 09:03 PM


Features
 

Advertising
 

Newsgroups
 


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