[英]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.