【发布时间】:2015-07-30 17:21:49
【问题描述】:
我一直在使用这样的行:
Cells.AutoFilter 11, "0"
暂时将第 11 列自动过滤为“0”。
我最近更新到 Microsoft Office 2013,现在我收到了 AutoFilter method of Range class failed 这一行的运行时错误。这是与 Office 2013 的兼容性问题还是其他问题?
编辑:我应该澄清一下,我没有收到我已经运行的程序的错误,而是我以前使用过但现在不适合我的行。
代码:
Dim firstRow As Integer
Dim lastRow As Integer
Dim firstCol As Integer
Dim lastCol As Integer
Dim allRange As Range
Dim vRange As Range
Dim bRange As Range
Dim commentsCol As Integer
Dim commentsColRng As Range
Dim fieldNameCol As Integer
Dim userCol As Integer
If Cells(2, 1) <> "" Then
firstCol = 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
firstRow = 2
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
commentsCol = Rows(1).find("Comments").Column '11
fieldNameCol = Rows(1).find("Field Name").Column '8
userCol = Rows(1).find("User").Column '4
Set allRange = Range(Cells(firstRow, firstCol), Cells(lastRow, lastCol))
Set commentsColRng = Range(Cells(firstRow, commentsCol), Cells(lastRow, commentsCol))
Cells.AutoFilter Field:=1, Criteria1:="PF"
Cells.AutoFilter commentsCol, "0", xlFilterValues
Cells.AutoFilter Field:=2, Criteria1:="0", Operator:=xlFilterValues
End If
我有三个自动过滤器,因为我尝试了多种不同的方式。
【问题讨论】:
-
嗯,这很奇怪。带有
Same代码的Same文件是否在Excel 2010 中工作? -
作为一个仅供参考,我刚刚提取了 Excel 2013 的副本并使用了诸如您的代码进行测试,它运行良好。您确定代码在
Activesheet上运行不是问题(隐含因为代码没有指定工作表),并且您实际上需要过滤不同的工作表吗?你确定第 11 列有数据吗? -
@SiddharthRout 我相信我们最初使用的是 Office 2003,所以我不知道 2010 年的情况。我之前编写的程序中也有类似的行。
Cells.AutoFilter Field:=2, Criteria1:="0", Operator:=xlFilterValues -
@user3561813 我会尝试指定一个工作表,但我知道第 11 列有数据
标签: vba excel autofilter office-2013