简体   繁体   中英

Using variable as a column for autofilter (vba)

I'd like to use a variable as a column for autofilter in vba, I think I'm not getting the sintax right, cause it`s not working:

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

If there are no blank columns, you can use the CurrentRegion instead (similar to a Ctrl + A in A1 )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM