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?
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