![](/img/trans.png)
[英]unable to get the Specialcells property of the range class for xlcelltypevisible
[英]Unable to get the SpecialCells Property of the Range class
我正在尝试在excel表格中获取过滤的行数。但是我正在尝试以下提到的错误:
无法获取Range类的SpecialCells属性。
strPath="C:\Users\PSin\Desk\CodeInven.xlsx"
Dim ObjectName
ObjectName=Trim(InputBox("Object Name:"))
Set objExcel= CreateObject("Excel.Application")
objExcel.Visible= True
objExcel.Workbooks.Open(strPath)
With objExcel.Activeworkbook.Sheets("All")
.Range("A1").AutoFilter 19,"="&ObjectName
Rowz = .AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1 'Not able to figure out the correct way
msgbox Rows
End With
如果您只是在寻找行数,则可以省去缩小检查范围,而仅获得可见行数。
Dim Rowz
With objExcel.ActiveWorkbook.Sheets("All")
With .Cells(1,1).CurrentRegion
.AutoFilter 19, "=" & ObjectName
Rowz = .Cells.SpecialCells(12).Rows.Count - 1 '<~~ VBScript might not know that xlCellTypeVisible = 12
MsgBox Rowz
End With
End With
我已经将xlCellTypeVisible减小为它的值,并通过向Range.CurrentRegion属性添加限制来删除列A的限制。 (顺便说一句,您的原始代码是MsgBox Rows
,而不是MsgBox Rowz
。最好是使用Option Explicit
以避免这种错别字)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.