Problem with getting row count using SpecialCells in filtered excel sheet

sharshra

Active Member
Joined
Mar 20, 2013
Messages
276
Office Version
  1. 365
I want to count the number of rows after filtering thru vb.net code. I have written the following simple function to return row count. But, it is behaving wierdly. It is working correctly, but in some cases it is returning some randon number. Can anybody help to get this fixed or suggest a better solution?
Code:
Private Function AccessSheetFiltered (ByVal dteFromDate As Date, ByVal dteTo Date As Date) As Integer
(declarations......
set range..........)
    With xlsDynRange
        .AutoFilter(Field:=1, _
                        Criteria1:=">=" & dteFromDate, _
                        Operator:=Excel.XlAutoFilterOperator.xlAnd, _
                        Criteria2:="<=" & dteToDate)
        xlsFilteredRangeInFunction = xlsWorksheet.Range("A:A").SpecialCells(Excel.XlCellType.xlCellTypeVisible)
            
        AccessSheetFiltered = xlsFilteredRangeInFunction.Range("A:A").SpecialCells(Excel.XlCellType.xlCellTypeVisible).Count
    End With
End Function
 
I had tried the option suggested by Mike. But, intellisence was not picking SpecialCells when I put dot after Columns(1). However, I just typed the entire line & it works. Probably, relying on intellisence stopped me trying other options. It was resolved on 1st Apr itself ......thanks to all resouceful guides like Mike in the forum. Apologies for responding late.

Just curious....... what could be the reason for intellisence not picking SpecialCells?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Just curious....... what could be the reason for intellisence not picking SpecialCells?

Intellisense seems to be quite flaky in its operation at times and any one of :-
1, Variable not defined/mis-spelt
2, Amending a previously keyed/copied line
3, Mis-spelt keyword

causes it not to activate.

As you have guessed it is best not relied upon!

hth
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,971
Members
449,059
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top