AutoFilter number range using two cell refs

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hi all
This is now driving me nuts !
I'm simply trying to AutoFilter column B (of range A:L) using two numbers placed in cells AA1 and AA2 (AA1 is the starting number and AA2 the ending)
VBA Code:
  ActiveSheet.Range("$A$1:$L$772").AutoFilter Field:=2, Criteria1:=Range("AA1").Value, Operator:=xlAnd, Criteria2:=Range("AA2").Value

However no matter how I format the code it won't filter any data correctly, actually shows nothing. BUT if I auto filter the column myself using NumberFilters>Between and enter the numbers in the "is after or equal to" (cell AA1 value) and "is equal to and before" (cell AA2 value) boxes, the filter works!

any help before I turn to drink, drugs and taking the fish for a walk !!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
When you are doing it manually you are doing a between, in your code you are doing an exact match. Try
VBA Code:
Range("$A$1:$L$772").AutoFilter 2, ">=" & Range("AA1").Value, xlAnd, "<=" & Range("AA2").Value
 
Upvote 0
When you are doing it manually you are doing a between, in your code you are doing an exact match. Try
VBA Code:
Range("$A$1:$L$772").AutoFilter 2, ">=" & Range("AA1").Value, xlAnd, "<=" & Range("AA2").Value

Brilliant - thanks a lot, I relised my error few minutes ago but was still struggling to adapt the code to find the range as opposed to exact match.

Appreactae the help - many thanks
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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