Autofilter using variable Criteria VBA

后端 未结 1 487
-上瘾入骨i
-上瘾入骨i 2021-01-16 09:59

I am trying to put an autofilter on a worksheet using a variable, but it is not working.

  Dim Criteria As Object
  i = 1
  Set Criteria = ActiveSheet.Cells(         


        
1条回答
  •  隐瞒了意图╮
    2021-01-16 10:34

    Get rid of the quote marks around your Criteria1 argument:

    ActiveSheet.Range("$A$1:$BM$204").AutoFilter Field:=2, Criteria1:=Criteria.Value
    

    Also, just a question why you would use late binding on a Range object? I do use late binding for objects that would require another library/reference, but since Range is part of the Excel object library, I would use early binding. I would Dim Criteria as Range but that's just my preference.

    0 讨论(0)
提交回复
热议问题