Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Delete rows based on more than one condition.

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Delete rows based on more than one condition.

On Sep 23, 9:05*am, thomas 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Delete rows based on more than one condition.

Steven,

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


Thomas



" wrote:

On Sep 23, 9:05 am, thomas 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Delete rows based on more than one condition.

On Sep 23, 8:59*pm, thomas wrote:
Steven,

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

Thomas

" wrote:
On Sep 23, 9:05 am, thomas 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to delete rows based on a condition marcia2026 Excel Programming 9 October 31st 09 10:54 AM
Delete Rows based on condition Vic Excel Discussion (Misc queries) 2 August 18th 09 08:54 PM
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
Delete worksheet row based on condition miek Excel Programming 3 August 23rd 07 07:16 PM
How to delete a data row based on a condition wmc New Users to Excel 4 April 18th 07 02:40 PM


All times are GMT +1. The time now is 03:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"