AutoFilter un-check boxes in filter

elawton

New Member
Joined
Nov 18, 2015
Messages
12
I am using the record macro feature to write the VB code so that I can delete the rows that contain values other than "55" or "56". What I want to do is deselect "55" and "56" (notice they are not displayed) and select every other value.

Columns("A:A").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$A$20734").AutoFilter Field:=1, Criteria1:=Array( _
"0", "1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "20", "21", "22", _
"23", "24", "25", "26", "27", "28", "29", "3", "30", "31", "32", "33", "34", "35", "36", "39", _
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "5", "52", "53", "54", "59", "6", _
"61", "62", "63", "64", "65", "66", "67", "68", "69", "7", "71", "72", "73", "74", "75", "76", _
"78", "79", "82", "83", "84", "85", "86", "87", "88", "89", "9", "90", "91", "94", "96", "97", _
"98"), Operator:=xlFilterValues
Rows("2:2").Select

I tried to modify the auto generated code (see below) but get the error "AutoFilter method of Range class failed"

Selection.AutoFilter
ActiveSheet.Range("$A$1:$A$20734").AutoFilter Field:=1, Criteria1:= _
"<55", Operator:=x1And, Criteria2:=">56"
Rows("2:2").Select

I imagine there is a pretty simple way to do this but I can't make it work.
Thanks
 

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.
You almost had it. You want to show everything less than 54 OR greater than 56.

Try this, based on Criteria for VBA AutoFilters. How to use AutoFilter Criteria in Excel VBA

Code:
Sub test()'http://www.ozgrid.com/VBA/autofilter-vba-criteria.htm
With ActiveSheet
    .AutoFilterMode = False
    .Range("A:A").AutoFilter
    .Range("A:A").AutoFilter Field:=1, Criteria1:="<55", _
     Operator:=[COLOR=#ff0000]xlOr[/COLOR], Criteria2:=">56"
End With
Rows("2:2").Select
End Sub
 
Upvote 0
Bill;
Thanks, that didn't work exactly as your code is written but got me close enough to solve the problem myself.
Ed
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,668
Members
448,977
Latest member
moonlight6

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