English 中文(简体)
当我使用AutoFilter特别轮椅在VBA中找到可见的囚室时
原标题:Error when I use SpecialCells of AutoFilter to get visible cells in VBA

我的主要目标是复制一个汽车过滤器的可见电池,随后将可见电池的尺寸复制到新版。 我正在使用这一法典:

Sheets(1).AutoFilterMode = False
Sheets(1).Range("A1:A1").AutoFilter Field:=columnaNumeroIntervalo, criteria1:=CDec(paramCantidadCriterio)
Sheets(1).Range("A1:A1").AutoFilter Field:=columnaNumeroIntervaloUnidades, Criteria1:=paramUnidadesCriterio

MsgBox AutoFilter.Range.SpecialCells(xlCellTypeVisible)(2, 11).Value

最后一条线,我要检查一个囚室的价值。 如果我使用<条码>Cells(2,11),而不是<条码>。 我可以看到,囚室有所有囚室,都看得见,而且看不到。 因此,我想使用<代码>特殊产品。

如果我使用特殊牢房,我会发现以下错误:

error -2147417848(80010108)在运行时间。 自动配对错误:

在执行类型时,它似乎陷入了 lo,最后造成这一错误。 也许,特委会会修改汽车过滤器,然后在每次改装中再次执行汽车过滤器?

最佳回答

如果你正在计划排除负责人,则须使用<>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

“entergraph

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

“enter

HTH

问题回答

暂无回答




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签