繁体   English   中英

VBA Autofilter Excel 2013吗?

[英]VBA Autofilter Excel 2013?

我一直在使用这样的一行:

Cells.AutoFilter 11, "0"

暂时将第11列自动过滤为“ 0”。

我最近更新到了Microsoft Office 2013,现在此行显示AutoFilter method of Range class failedAutoFilter method of Range class failed运行时错误。 这是与Office 2013的兼容性问题还是其他一些问题?

编辑:我应该澄清,我不是已经运行的程序出现错误,而是我以前使用过的行,现在对我不起作用。

编辑2: 我正在处理的电子表格

码:

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

我有三个自动过滤器,因为我正在尝试多种不同的方法。

您在第11栏中可能没有任何内容。

例如:

     A         B
---------------------
1  field1   field2
2  a             0 
3  b             1
4  c             2
5  d            23

Sub Test()
    ' this will succeed because column 2 (B) has something
    Cells.AutoFilter 2, "0"

    ' this will fail because column 3 (C) has nothing to filter on
    ' error message will be AutoFilter method of Range class failed
    Cells.AutoFilter 3, "0"
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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