I am trying to get the filtered rows count in the excel sheet.But I am trying below mentioned error :
Unable to get the SpecialCells Property of the Range class.
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
If you are just looking for a row count, you can dispense with cutting down the examined range and just get a count of the visible rows.
I've reduced the xlCellTypeVisible to its value and removed the column A restriction by adding a restriction to the Range.CurrentRegion property. (btw, your original code was
MsgBox Rows
, notMsgBox Rowz
. Probably best to useOption Explicit
to avoid typos like that).