Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50194

creating a variable drop autofilter

$
0
0
Hi

i am trying to create a variable autofilter, in VBA, but having some issues with it, when i recorded it, got the following:

HTML Code:

"Columns("B:C").Select
Selection.AutoFilter
ActiveSheet.Range("$B$1:$C$1533").AutoFilter field:=2, Operator:= _
xlFilterValues, Criteria2:=Array(2, "8/5/2013", 2, "8/6/2013", 2, "8/7/2013")"

so i changed the variable and it still worked:
HTML Code:

RC = Application.WorksheetFunction.CountA(Range(Cells(1, 2), Cells(90000, 2).End(xlDown)))
ActiveSheet.Range(Cells(2, 1), Cells(1 + RC, 3)).AutoFilter field:=2, Operator:= _
xlFilterValues, Criteria2:=Array(2, "8/5/2013", 2, "8/6/2013", 2, "8/9/2013")

it stopped working when i go to change the dates to variables:


HTML Code:

dat1 = ThisWorkbook.Worksheets("Sheet2").Range("a1")
dat2 = ThisWorkbook.Worksheets("Sheet2").Range("a2")
dat3 = ThisWorkbook.Worksheets("Sheet2").Range("a3")
dat4 = ThisWorkbook.Worksheets("Sheet2").Range("a4")


RC = Application.WorksheetFunction.CountA(Range(Cells(1, 4), Cells(90000, 4).End(xlDown)))
Selection.AutoFilter
ActiveSheet.Range(Cells(1, 1), Cells(1 + RC, 54)).AutoFilter field:=3, Operator:= _
xlFilterValues, Criteria1:=Array(dat1, dat2, dat3, dat4)

any ideas as to what i am doing wrong????????

Viewing all articles
Browse latest Browse all 50194

Trending Articles