• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter data using Between and delete the entire row

Hi Team,

Pls help on clear this macro
trying to filter between <=-50 to <=-5, if once selected i need to delete the entire row.
But iam getting error "Object Variable or with block variable not set"

enclosed sample file for reference.

Code:
Option Explicit

Sub filter1()
Dim ws As Worksheet
Dim LR As Long

ws.Range("A1:M").AutoFilter Field:=12, Criteria1:=">=-50", Operator:=xlAnd, Criteria2:="<=-5"

ws.Range("A2.M" & LR).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
 
End Sub

Sub filter2()
Dim ws As Worksheet
Dim LR As Long

ws.Range("A1:M").AutoFilter Field:=12, Criteria1:=">=5", Operator:=xlAnd, Criteria2:="<=50"

ws.Range("A2.M" & LR).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    
End Sub
 

Attachments

  • Test.xlsb
    14.2 KB · Views: 1
jawaharprm
Could You check Yourself next:
# filter between <=-50 to <=-5
Which values do You mean?

# Criteria1:=">=-50", Operator:=xlAnd, Criteria2:="<=-5"
# Criteria1:=">=5", Operator:=xlAnd, Criteria2:="<=50"
Should above be same as You've written?

# Range("A1:M")
There is only M ... hmm?

# Range("A2.M" & LR)
What is between 2 & M ?
 
Hi Sir,
Criteria has to filter in L Column and once filtered the visible rows should be deleted.
i have made some correction in code.
Code:
Sub filter1()

Sheet3.Select
    Selection.AutoFilter
    Range("L1").Select
    ActiveSheet.Range("$A$1:$L$10000").AutoFilter Field:=12, Criteria1:=">=-50", Operator:=xlAnd, Criteria2:="<=-5"
  
End Sub
 
jawaharprm
The Excel is many times very sensitive,
but for good reason.
You seems to skip my wonderings.
I'll try one more time...
Did You find any values from Your sample data which match with Your writing or code?
Have You tried to solve that manually?
... if Yes, then ... which values / rows did You get?
As You one idea is to ... Delete ... something,
then You should also test with a sample data - what will happen / should happen, if there are none rows after filtering with Your code?
... of course, You have backups.
 
Last edited:
Back
Top