首页 > 解决方案 > 使用变量表示列号的自动过滤器

问题描述

我正在尝试用 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

标签: vbalong-integerautofilter

解决方案


请尝试下一个方法:

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

Cells参数RowIndex后跟ColumnIndex.


推荐阅读