PC Review


Reply
Thread Tools Rate Thread

Count Dates in a range

 
 
Jim G
Guest
Posts: n/a
 
      14th Nov 2008
I'm, trying to count dates in a column to determine the number of dates after
the current date in order to present the user with a messge to check for
overdue jobs and the number of jobs due today, when the sheet is opened or
activated. I testing the following code:

Sub CountDates()

Dim Dt As Date

Dt = Date ' todays date

With Worksheets("Jobs")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'last row of job data
End With

Set StartCell = Range("Q4") ' starting range
Set Endcell = Range("Q" & LastRow) 'ending range
oDue = Application.WorksheetFunction.CountIf(Range(StartCell, Endcell), "<"
& Dt) 'counts the number of dates earlier than today

MsgBox oDue & " Jobs are overdue"

End Sub

I have ensured that the dates are entered in each cell as a date dd/mm/yyy.
The result is always 0 using "<" or ">". If text is entered in the range (a
heading) it returns a positive count with ">" but not "<". Strangley
Application.WorksheetFunction.CountIf(Range(StartCell, Endcell), Dt) counts
the correct number of dates = to Dt.

The result I'm looking for is a message "There are N jobs due today and N
jobs are overdue".

I'm using XL2007

Any ideas or other solutions
--
Jim
 
Reply With Quote
 
 
 
 
Jim G
Guest
Posts: n/a
 
      14th Nov 2008
Thanks rylo,

I don't know how you knew that but it works.

Is there a place I should have been able to find this knowledge intuitively?

MS XL drives me nuts, but I can't live without it!!

--
Jim


"rylo" wrote:

>
> Jim
>
> In your test code try using
>
>
> Code:
> --------------------
> oDue = Application.WorksheetFunction.CountIf(Range(StartCell, Endcell), "<" & Format(Dt, "0")) 'counts the number of dates earlier than today
> --------------------
>
>
> If that works, then expand for your full requirement.
>
> HTH
>
> rylo
>
>
> --
> rylo
> ------------------------------------------------------------------------
> rylo's Profile: http://www.thecodecage.com/forumz/member.php?userid=28
> View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=29459
>
>

 
Reply With Quote
 
Jim G
Guest
Posts: n/a
 
      16th Nov 2008
I seems your reply on 'thecodecage.com' has an extra line not in this forum.

The but I was refering to was knowing how to use '& Format(Dt, "0")) ' to
get the to get the code to work. I couldn't find this anywhere in Excel.

I was aware of the active sheet issue, in this case "Jobs" is always the
active sheet. However, I get point and have had a similar painful experience
and should change it.

BTW: how does this thread end up in 'thecodecage.com'?


--
Jim


"rylo" wrote:

>
> Hi
>
> Not sure which but you were referring to, but if it is making sure you
> are on the right sheet, then it was just painful experience!!!!
>
>
> rylo
>
>
> --
> rylo
> ------------------------------------------------------------------------
> rylo's Profile: http://www.thecodecage.com/forumz/member.php?userid=28
> View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=29459
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
count number of dates in range Sunflower Microsoft Excel Worksheet Functions 2 24th Mar 2010 06:07 PM
Count of in Range of Dates sonofroy Microsoft Access Queries 17 25th Sep 2009 03:13 PM
How do I get a count of dates within a range..? cmharri123 Microsoft Excel Worksheet Functions 2 1st Feb 2006 11:22 AM
How do I count in a range of dates? =?Utf-8?B?bmFuY3k=?= Microsoft Excel Worksheet Functions 2 23rd Nov 2005 11:03 AM
How to count dates within a certain range in a column with mutiple date range entries Krisjhn Microsoft Excel Worksheet Functions 2 1st Sep 2005 01:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:13 AM.