VBA Autofilter not working! (3 criteria Array)

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
Office Version
  1. 365
Platform
  1. Windows
Calamity!

Have this autofilter:

VBA Code:
Range("A1:W" & Lastrowaf1).AutoFilter field:=12, Criteria1:=Array(bkdate, bkdate2, bkdate3), Operator:=xlFilterValues ' Booking Date

Lastrowaf1 is working (12,000 rows), field 12 is the autofilter field (contains date as serial, 44242 etc)

bkdate, bkdate2 and bkdate3 are all declared as LONG and their variables are:

bkdate - 44242
bkdate2 - 44235
bkdate3 - 44228

So each date a week before.

The data in the filter has dates that go from 44200 to 44256, each in 7 day increments and yes, 44242, 44235 and 44228 all appear.

Unfortunately, when I run the line of code above the autofilter returns a blank result.

If I take off "Operator:=xlFilterValues" I then only get 44228 returning, even though there are valid lines for bkdate and bkdate2.


So I'm stuck, any help?

Full code extract:

VBA Code:
'Calculate origin of bookings, booking by booking

t3.Activate
Range("D:D").NumberFormat = "dd/mm/yyyy"
Range("J:J").NumberFormat = "£#,##0.00"
Range("L:L").NumberFormat = "dd/mm/yyyy"
Range("A3").Activate
Dim strow, erow, bkdate, bkdate2, bkdate3 As Long
Dim csheet As Worksheet
Dim web, london, other As Boolean


Do Until Cells(ActiveCell.Row, "A").Value = ""

bkdate = CLng(Cells(ActiveCell.Row, "L").Value)
bkdate2 = bkdate - 7
bkdate3 = bkdate - 14
tnam = Cells(ActiveCell.Row, "N").Value
pup = Cells(ActiveCell.Row, "E").Value
src = Cells(ActiveCell.Row, "F").Value

af1.Activate
Range("A1:W" & Lastrowaf1).AutoFilter field:=12, Criteria1:=Array(bkdate, bkdate2, bkdate3) ' Booking Date
Range("A1:W" & Lastrowaf1).AutoFilter field:=3, Criteria1:=tnam ' Tour Name
Range("A1:W" & Lastrowaf1).AutoFilter field:=15, Criteria1:="*" & pup & "*" ' Pickup
Range("A1:W" & Lastrowaf1).AutoFilter field:=23, Criteria1:=src ' Source code

    If something Then
    
    
    
    End If

ActiveCell.Offset(1, 0).Activate
Loop ' main loop

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ok so apparently, you can't filter >2 criteria on a column, and you can't use an array for variable numerical inputs (to my knowledge), so I've basically used a simpler solution of saying:

>= earliest given date and <= latest given date.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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