VBA-Autofilter with text not working when excluding

JaapZ

New Member
Joined
Apr 21, 2016
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Good afternoon, finding myself in a "smash head on keyboard to continue"-situation.
I'm filtering a dataset on various columns. In one it has to exclude all rows where the cell value in the column reads "Don't use". The cell contents are entered via a formula which looks in another cell.
The formula in the column I'm evaluating (column 23) is"
Code:
[I][SIZE=2][FONT=Verdana]=IF('Latest Download'!$Txx=2,'Latest Download'!ALxx,"Don't use")[/FONT][/SIZE][/I]

The filter I'm applying in my macro is the following:
Rich (BB code):
    ActiveSheet.Range("$A$1:$BB$12001").AutoFilter Field:=23, _ 
Criteria1:=Array(<>"*Don't*"), Operator:=xlFilterValues
<strike></strike>

And that throws me an error.

Stupid thing is that when I change that line so that only the "Dont's" are to be selected, it works correctly.
Code:
[I][FONT=Verdana]    ActiveSheet.Range("$A$1:$BB$12001").AutoFilter Field:=23, _
        Criteria1:=Array("*Don't*"), Operator:=xlFilterValues[/FONT][/I]

I've gone through many messages on many forums: no succes.
Anyone who can explain me what I'm doing wrong and what I need to change to make it work?

Regards,

Jaap
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try
Code:
ActiveSheet.Range("$A$1:$BB$12001").AutoFilter 23, "<>*Don't*"
 
Upvote 0
Good afternoon Fluff, that throws me a compile error. :eeek:
 
Upvote 0
In that case can you please supply the entire code?
 
Upvote 0
Hello, herewith the total pice of code for that filter.
Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]' Refresh filter on "Working Document"
    Sheets("Working Document").Select
    ' Remove existing filters on Worksheet "Working Document"
    If ActiveSheet.FilterMode Then
        ActiveSheet.ShowAllData
    End If
    ' Set new filter
    ActiveSheet.Range("$A$1:$BB$12001").AutoFilter Field:=3, _
        Criteria1:=Array("PC3300", "PC3340", "PC3400", "PC3500"), Operator:=xlFilterValues
    ActiveSheet.Range("$A$1:$BB$12001").AutoFilter Field:=23, _
        Criteria1:=("<>*Don't*"), Operator:=xlFilterValues
    ActiveSheet.Range("$A$1:$BB$12001").AutoFilter Field:=34, _
        Criteria1:=("<>0"), Operator:=xlFilterValues
[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
[/FONT]Funny thing is: when I copied the piece for the filter on column 34 and pasted that back to make the filter for column 23 (to make sure that there were no typing errors), I accidentally left the "34".
Means that the "*Don't*"-filter was now applied to column 34 instead of 23. No error. Might it have something to do with the formatting of column 23? That's currently formatted as a date.
 
Upvote 0
With that code you should not be getting a compile error.
What exactly is the message & what is highlighted?
 
Upvote 0
Ok, I must have been intoxicated, as now it does indeed work as expected. Flabbergasted.
Thanks for answering, as in the end I've got it to work.
 
Upvote 0
Glad it's working & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top