如果你正在计划排除负责人,则须使用<>Offset。 您正在发现的错误是,你在“密码”之前就失踪了。
~~> Remove any filters
ActiveSheet.AutoFilterMode = False
~~> Filter,
With rRange
.AutoFilter Field:=1, Criteria1:=strCriteria
~~> offset(to exclude headers)
Debug.Print .Offset(1, 0).SpecialCells(xlCellTypeVisible).Cells(2,11).Value
Debug.Print .SpecialCells(xlCellTypeVisible).Cells(2,11).Value
End With
~~> Remove any filters
ActiveSheet.AutoFilterMode = False
我决定作为这一答复的一部分添加这一内容,以便今后能够帮助其他人。
让我们说,我们的范围是全面的。
A1:F6
When you run the below code, depending on whether you are using Offset
or not, you will get these results.
Option Explicit
Sub Sample()
~~> Remove any filters
ActiveSheet.AutoFilterMode = False
Dim rRange As Range
Dim Rnge As Range
Set rRange = Sheets("Sheet1").Range("A1:F6")
~~> Filter,
With rRange
.AutoFilter Field:=1, Criteria1:="<>2"
~~> Offset(to exclude headers)
Set Rnge = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
Debug.Print Range(Rnge.Address).Address
Debug.Print ActiveSheet.Cells(3, 2).Address
Debug.Print Range(Rnge.Address).Cells(3, 2).Address
Debug.Print "--------------------------------------------------"
~~> To include headers
Set Rnge = .SpecialCells(xlCellTypeVisible)
Debug.Print Range(Rnge.Address).Address
Debug.Print ActiveSheet.Cells(3, 2).Address
Debug.Print Range(Rnge.Address).Cells(3, 2).Address
End With
~~> Remove any filters
ActiveSheet.AutoFilterMode = False
End Sub
HTH