+ Reply to Thread
Results 1 to 15 of 15

Looking for a formula that counts between two times

  1. #1
    Registered User
    Join Date
    03-18-2011
    Location
    Atlanta Georgia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Looking for a formula that counts between two times

    Hi All,
    You guys were such great help on my last issue, that I am coming back for more. :-) I researched how I might do this, but keep getting stumped by part of it.
    I have data over the last 170 days. Each entry has a time stamp. I would like to count how many entries there are between 7:45 am and 2:45pm. A total count across all 170 days is needed, but it would be great if I could break that down by calendar day (i do have that as a column).
    Here is a sample of the data:Friday 11/15/13 07:08AM
    Friday 11/15/13 07:08AM
    Friday 11/15/13 07:16AM
    Friday 11/15/13 07:16AM
    Friday 11/15/13 07:46AM
    Friday 11/15/13 07:46AM

    And the sheet has dates starting in June and ending in mid December.

    Thanks for suggestions.
    Scott

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Looking for a formula that counts between two times

    Try this:
    Please Login or Register  to view this content.
    and of course - if you would attach a file the formula would have addres to real data. Once there was no attachment you shall instead of A1:A170 put real address of the data for particular day (or add yet another factor inside sumproduct to count for particular day) and test formula by yourself
    Last edited by Kaper; 12-19-2013 at 09:22 AM.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    Suppose your example data is in column A and is actual Excel-dates formatted to look like that, and your list of calendar dates is in column D, starting in D2, then you can put this formula in E2:

    =SUMPRODUCT((INT(A$1:A$1000)=D2)*(MOD(A$1:A$1000,1)>=--"7:45:00")*(MOD(A$1:A$1000,1)<=--"14:45:00"))

    Adjust the cell references to suit, then copy down.

    Hope this helps.

    Pete

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Looking for a formula that counts between two times

    The other option is to do a pivot table out of the data. Filtering timestamps between certain hours could be a bit tricky, but the result will be neatly formatted and include all data just in one step (without creating manually list of dates). Anyway, again sample data in a spreadsheet would make answering easier/more precise.

  5. #5
    Registered User
    Join Date
    03-18-2011
    Location
    Atlanta Georgia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looking for a formula that counts between two times

    Quote Originally Posted by Pete_UK View Post
    Suppose your example data is in column A and is actual Excel-dates formatted to look like that, and your list of calendar dates is in column D, starting in D2, then you can put this formula in E2:

    =SUMPRODUCT((INT(A$1:A$1000)=D2)*(MOD(A$1:A$1000,1)>=--"7:45:00")*(MOD(A$1:A$1000,1)<=--"14:45:00"))

    Adjust the cell references to suit, then copy down.

    Hope this helps.

    Pete
    Each date element is in its own cell.
    Time is one column, date is one column, and day is one column.
    Does that help??
    Thanks
    Scott

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    Attach a sample workbook.

    Pete

  7. #7
    Registered User
    Join Date
    03-18-2011
    Location
    Atlanta Georgia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looking for a formula that counts between two times

    Here is a sample.
    Thanks
    Scott
    Attached Files Attached Files

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    Your "times" in column C are text values - to convert them to proper times you can put this formula in D2:

    =(LEFT(C2,5)&":00")+IF(RIGHT(C2,2)="PM",0.5,0)

    Format that cell as TIME, then copy the formula down.

    You can derive the dates in column F using this formula in F2:

    =MIN(B:B)

    and this one in F3:

    =F2+1

    Format both cells as dates, then copy the formula in F3 down as far as you need. Then in G2 you can have this formula:

    =SUMPRODUCT((B$2:B$400=F2)*(D$2:D$400>=--"7:45:00")*(D$2:D$400<=--"14:45:00"))

    (which results in 90 in your sample file), then copy this down for as many dates as you have in column F.

    Hope this helps.

    Pete

  9. #9
    Registered User
    Join Date
    03-18-2011
    Location
    Atlanta Georgia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looking for a formula that counts between two times

    Pete, it worked for cells G2 and G3, but after that it returned a 0 in each cell. There is data for these dates, but for some reason the formula only picked up the first 2 in the column.
    I have attached the worksheet. It has about 4100 rows.
    Any thoughts?
    Thanks
    Scott
    Attached Files Attached Files

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Looking for a formula that counts between two times

    other way to have real time from "time like text":
    Please Login or Register  to view this content.
    Check out in attached file, how (with 2 IFs) it could be used in Pivot Table.
    Attached Files Attached Files

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    Quote Originally Posted by scott3294 View Post
    ... but for some reason the formula only picked up the first 2 in the column...
    That's because the formula is only looking at the ranges down to row 400. Change 400 to 4400 (3 times) in the formula in G2, then copy it down again.

    Hope this helps.

    Pete

  12. #12
    Registered User
    Join Date
    03-18-2011
    Location
    Atlanta Georgia
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looking for a formula that counts between two times

    Thanks Pete!!
    Again, this group is fantastic.
    Thanks for all the help.
    Scott

  13. #13
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    You're welcome, Scott - glad you got it working.

    If that takes care of your original question, please select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Also, since you are relatively new to the forum, I would like to inform you that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

  14. #14
    Forum Contributor
    Join Date
    01-28-2008
    MS-Off Ver
    Excel 365
    Posts
    157

    Re: Looking for a formula that counts between two times

    This seems simpler (F2 is the date, 12/2/2013):

    Please Login or Register  to view this content.

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Looking for a formula that counts between two times

    The OP's version is XL2003 in his profile, and COUNTIFS was not available in that version (I know he subsequently attached an .xlsx file).

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 11-14-2011, 05:40 PM
  2. Counts how many times i enter a number in a particular cell
    By j0hn in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-13-2010, 02:25 PM
  3. Replies: 9
    Last Post: 03-16-2010, 03:34 PM
  4. formula that counts
    By excellentexcel in forum Excel General
    Replies: 6
    Last Post: 01-13-2009, 09:48 AM
  5. A cell that counts the number of times...
    By TPD in forum Excel General
    Replies: 1
    Last Post: 02-14-2005, 11:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1