使用变量来表示列号的自动过滤器

Auto Filter using a variable to represent column number

我试图在下面的自动筛选代码中用 Long 替换命名列“I”:

With Range("I1", Range("I" & Rows.Count).End(xlUp))
    .AutoFilter 1, TeamString
End With

我已将 "filterColumn" 定义为 Long。但是我得到一个 运行 时间错误:对象失败的方法范围,因为我在下面对变量的引用不正确:

With Range(Cells(filterColumn, 1), Range(filterColumn & Rows.Count).End(xlUp))
    .AutoFilter 1, filterEntry
End With

请尝试下一种方式:

With Range(Cells(1, filterColumn), Cells(Rows.Count, filterColumn).End(xlUp))
    .AutoFilter 1, filterEntry
End With

Cells参数是RowIndex后跟[=​​13=].