使用变量作为自动过滤器的列(vba)

时间:2017-03-06 00:37:52

标签: excel vba excel-vba autofilter

我想在vba中使用变量作为autofilter的列,我想我没有把sintax正确,因为它不起作用:

With ActiveSheet
.AutoFilterMode = False
With .Range("A1:" & LastCol + 1 & "1")
.AutoFilter
.AutoFilter field:=5, Criteria1:="Approved"
.AutoFilter field:=6, Criteria1:="Open"
.AutoFilter field:=LastCol + 1, Criteria1:="1"
End With
End With

1 个答案:

答案 0 :(得分:1)

如果没有空白列,则可以改为使用CurrentRegion(类似于A1中的Ctrl + A)

ActiveSheet.AutoFilterMode = False
With Cells.CurrentRegion
    .AutoFilter 5, "Approved"
    .AutoFilter 6, "Open"
    .AutoFilter .Columns.Count, "1"
End With