Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Autofilter and Cell Count

I have the following code that uses the "Autofilter" method to sort dates
(Sdate and Edate). After it filters the data, I use a counter to count the
number of occurrences and use a msgbox to display the number of records. The
problem is that the numbers don't seem to jive with the #records shown at the
bottom of the screen.
I even set an initial number to the counter (cnt =1 ) to help it along, but
the count is still very erratic. Please help.

Sub DateDifferences()

Dim LastRow As Long, Row As Long
Dim cnt As Long
Dim SDate As String
Dim EDate As String


SDate = InputBox("Enter Starting Date as m/d/yyyy")
EDate = InputBox("Enter Ending Date as m/d/yyyy")


ActiveSheet.Range("L3:L10000").Select
Selection.AutoFilter _
Field:=1, Criteria1:="=" & SDate, Operator:=xlAnd _
, Criteria2:="<=" & EDate
cnt = 1
LastRow = Range("A10000").End(xlUp).Row
For Row = 1 To LastRow
If (Cells(Row, 12).Value) = SDate And Cells(Row, 12).Value <= EDate Then
cnt = cnt + 1
Debug.Print cnt
End If

Next Row
MsgBox cnt
Selection.AutoFilter

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Autofilter and Cell Count

Better to just determine the number of visible rows:

MsgBox Range("A2",
Range("A65536").End(xlUp)).SpecialCells(xlCellType Visible).Count

I started with A2 assuming there's a header in A1. This assumes at least
one visible row.

--
Jim
"asmenut" wrote in message
...
|I have the following code that uses the "Autofilter" method to sort dates
| (Sdate and Edate). After it filters the data, I use a counter to count the
| number of occurrences and use a msgbox to display the number of records.
The
| problem is that the numbers don't seem to jive with the #records shown at
the
| bottom of the screen.
| I even set an initial number to the counter (cnt =1 ) to help it along,
but
| the count is still very erratic. Please help.
|
| Sub DateDifferences()
|
| Dim LastRow As Long, Row As Long
| Dim cnt As Long
| Dim SDate As String
| Dim EDate As String
|
|
| SDate = InputBox("Enter Starting Date as m/d/yyyy")
| EDate = InputBox("Enter Ending Date as m/d/yyyy")
|
|
| ActiveSheet.Range("L3:L10000").Select
| Selection.AutoFilter _
| Field:=1, Criteria1:="=" & SDate, Operator:=xlAnd _
| , Criteria2:="<=" & EDate
| cnt = 1
| LastRow = Range("A10000").End(xlUp).Row
| For Row = 1 To LastRow
| If (Cells(Row, 12).Value) = SDate And Cells(Row, 12).Value <= EDate
Then
| cnt = cnt + 1
| Debug.Print cnt
| End If
|
| Next Row
| MsgBox cnt
| Selection.AutoFilter
|
| End Sub
|


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoFilter and row count Bob Excel Discussion (Misc queries) 5 March 29th 07 12:40 AM
Count Not Appearing when using AutoFilter? BBob Excel Worksheet Functions 3 July 14th 05 11:56 PM
Autofilter record count Debbie Thompson Excel Discussion (Misc queries) 1 February 11th 05 05:32 PM
Count of results in AutoFilter andrew Excel Programming 3 October 2nd 04 12:45 AM
autofilter range count pauluk[_14_] Excel Programming 3 March 5th 04 01:33 AM


All times are GMT +1. The time now is 03:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"