Solved

Autofilter on cells not equal to

Posted on 2011-09-13
12
472 Views
Last Modified: 2012-05-12
I am finishing an autofilter and had a late add.  In the code, I need to add a line that gives me only the cells that do have the text REJ in it.  There are numerous other values in the same cell, I just do not want the ones that have REJ as part of it.
With rgFilter
        .AutoFilter
        .AutoFilter Field:=7, Criteria1:="SPCLMDL"
                .AutoFilter Field:=10, Criteria1:=Array( _
        "CRTD", "PCNF LKD  REL", "PCNF REL", "REL"), Operator:=xlFilterValues
        .AutoFilter Field:=20, Criteria1:="<=" & Date, Operator:=xlAnd  'Late including today
        
        .Sort Key1:=Range("T1"), Order1:=xlAscending, Header:=xlGuess, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin

'Need to filter by not-equal to REJ in column 31, if the value REJ is anywhere in any cell in this column
'Sample data is   CNF REJ PCNF REL could be in any cell.
        
    End With

Open in new window

0
Comment
Question by:RWayneH
  • 6
  • 4
  • 2
12 Comments
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
On which column are you going to apply this new filter ?
0
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
Sorry, did no see you code, which already has the answer. !! My bad.
0
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
Please add the following code in the same block

  .AutoFilter Field:=31, Criteria1:="=*REJ*", Operator:=xlAnd
0
 

Author Comment

by:RWayneH
Comment Utility
So  ="=*REJ*"  means not equal too?  and ="*REJ*" means equal too?  Can you please explain the line?  It will help me understand this for future filters..  thanks. -R-
0
 
LVL 10

Accepted Solution

by:
SANTABABY earned 500 total points
Comment Utility
If you want to dsiplay the cells that CONTAIN "REJ", Use => Criteria1:="=*REJ*"

If you want to dsiplay the cells that DO NOT CONTAIN "REJ", Use => Criteria1:="<>*REJ*"

0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
Are you after the cells that contain only REJ and nothing else?

If so:

.AutoFilter Field:=31, Criteria1:="=*REJ*", Operator:=xlAnd, Criteria2:="<>* *"

Thanks
Rob H
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
Actually just realised that if its those with only REJ it would be:

.AutoFilter Field:=31, Criteria1:="=REJ"

If the REJ could have trailing spaces then add an * after the J. This will show all cells that start with REJ.

I am guessing that you are producing a list from SAP showing Release Status of items eg Network or Activity. Can you use the Dynamic selection in SAP to generate the list with only REJ status?

Unfortuntely no longer have access to the PS module of SAP to help find the necessary criteria.

Thanks
Rob H
0
 

Author Comment

by:RWayneH
Comment Utility
Looking for whether "REJ" is anywhere in the contents of a cell.  Ex ( REL CNF LKD REJ)  would return True
If true filter it out.  ( REL CNF LKD ) = False  REJ not in the cell so show it.  -R-
0
 

Author Comment

by:RWayneH
Comment Utility
See the code above, I want to add this to the existing filters.. -R-
0
 

Author Comment

by:RWayneH
Comment Utility
.AutoFilter Field:=31, Criteria2:= _
        "<>*REJ*", Operator:=xlAnd

is failing,  when I use criteria1 it fails too...  I got the line from the macro recorder.  Maybe I need to understand the CriteriaX number? -R-

With rgFilter
        .AutoFilter
        .AutoFilter Field:=7, Criteria1:="SPCLMDL"
                .AutoFilter Field:=10, Criteria1:=Array( _
        "CRTD", "PCNF LKD  REL", "PCNF REL", "REL"), Operator:=xlFilterValues
        .AutoFilter Field:=20, Criteria1:="<=" & Date, Operator:=xlAnd  'Late including today
        
        .Sort Key1:=Range("T1"), Order1:=xlAscending, Header:=xlGuess, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin

'Need to filter by not-equal to REJ in column 31, if the value REJ is anywhere in any cell in this column
'Sample data is   CNF REJ PCNF REL could be in any cell.
        
    End With

Open in new window

0
 

Author Comment

by:RWayneH
Comment Utility
It was a different issue...  the
.AutoFilter Field:=31, Criteria1:="<>*REJ*", Operator:=xlAnd

worked to remove the rows that REJ showed in.  -R-
0
 

Author Closing Comment

by:RWayneH
Comment Utility
Thanks for the help w/ this.  -R-
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now