Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofilter criteria in Excel

Status
Not open for further replies.

mdgabe

Technical User
Sep 7, 2006
12
US
I want to autofilter based on criteria that is not equal to what I select, can someone help me with the syntax, my code reads as follows, basically I have a combobox that has a list of numbers, if the user chooses one of those numbers, I want this code to work and filter sheet 3, row 3, column 3 on all values except the one teh user chooses, this way I can then have code to delete visible cells. This not equal to is not working, it seems easy to filter on a value but not vice versa, I tried the macro recorder and it seemed that quotes were needed, so I tried to add quotes around my value to see whether that would make a difference. Appreciate any insights!

Code:
Private Sub Select_Terr(sTerr As String)
     On Error Resume Next
   Dim sterr1 As String
    Dim addq As String
 addq = """"
sterr1 = addq & "<>" & sTerr & addq

    Worksheets(3).Activate
    ActiveSheet.ShowAllData
    With ActiveWorkbook.Sheets(3)
        If sTerr <> "All" Then
            .Rows("3:3").Select
            Selection.AutoFilter Field:=3, Criteria1:=sterr1, Operator:=xlAnd
            
        End If
    End With
       On Error GoTo 0
    Worksheets(1).Activate
End Sub
 


Hi,

"...if the user chooses one of those numbers, I want this code to work and filter sheet 3, row 3, column 3 on all values except the one teh user chooses,..."

So if the user selects 3, you want to filter all values except 3?
Code:
Selection.AutoFilter Field:=3, Criteria1:=sTerr

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
I discovered that my problem is numbers are appearing as text in my worksheet in that column
 




Do you have BOTH numeric and string data in the same column?

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top