+ Reply to Thread
Results 1 to 17 of 17

Smallest value in range above criteria

  1. #1
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Smallest value in range above criteria

    I have a range of cells with time values like so:

    15:01:10; 15:01:12; 15:01:13; 15:01:15; 15:01:16; 15:01:17; 15:01:21; 15:01:22; 15:01:23;

    I need to find the smallest time value above my criteria 15:01:13 (in cell A11). So this would be 15:01:15.

    I am using =SMALL(A1:A9,COUNTIF(A1:A9,"<"&A11)+1) but it just returns the smallest time value in the range, not the smallest time value above my criteria. It doesn't seem to like the value in A11, even though I have formatted the cell exactly as the cells in the range. Can anyone shed some light on this please?
    Last edited by NBVC; 03-15-2012 at 02:20 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Smallest value in range above criteria

    Try:

    =MIN(IF(A1:A9>A11,A1:A9))

    confirmed with CTRL+SHIFT+ENTER not just ENTER
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    Still just gives me the lowest time value in the range 15:01:10. Confirmed with CTRL-SHFT-ENTR as well

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,696

    Re: Smallest value in range above criteria

    If they are all actual time values then I would expect your formula to work.....except you should use <= like

    =SMALL(A1:A9,COUNTIF(A1:A9,"<="&A11)+1)

    If that doesn't work you can check whether the cells are times (numbers), Try using

    =ISNUMBER(A11)

    how are the times generated/do they contain dates too?
    Audere est facere

  5. #5
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    It works with whole numbers or 2 x decimals like 00.00 but not the time value. It seems to be ignoring the time value I'm specifying as a criteria. I tried =COUNTIF(A1:A9,"<="&A11) to see if I even get a value but it returns 00:00:00. The cells in the range are formatted as time values but are RTD fields.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,696

    Re: Smallest value in range above criteria

    I don't know what RTD is....

    Does this work

    =MIN(IF(MOD(A1:A9,1)>MOD(A11,1),MOD(A1:A9,1)))

    confirmed with CTRL+SHIFT+ENTER

  7. #7
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    No it still only returns the lowest in the range. I manually typed in 15:01:13 into A11 and removed any formatting and the cell now shows 30-11-1999 15:01:13PM but it works. A11 needs to be a formula that results in a time value which does not work. It has to be a cell formatting issue or something.

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,696

    Re: Smallest value in range above criteria

    What formula are you using in A11?

  9. #9
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    In A13 I have =now()
    In A14 I have 00:00:10
    In A11 I have A13-A14

  10. #10
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    I am trying to get a time value that is 10 seconds ago in A11. It needs to be dynamic because it will always change

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,696

    Re: Smallest value in range above criteria

    =NOW() generates the current time and date so that means that A11 contains a date (whether you format the cells to show that date or not) so that's why all your times are deemed to be < A11, the date value makes A11 a much larger value than you expect.

    I would expect the last formula I suggested, i.e.

    =MIN(IF(MOD(A1:A9,1)>MOD(A11,1),MOD(A1:A9,1)))

    to work because the MOD function extracts just the time from the time and date.......but you could do that in the A11 formula, e.g. make that

    =MOD(A13-A14,1)

    That should still show the same time as before but it won't now contain a date, so your original formula should work, presumably A1:A9 are just times?

    Note: If you want it to be truly dynamic you probably need VBA to periodically update the current time, it won't update otherwise....

  12. #12
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    I wrapped the RealTimeData(RTD) links in mod(cell,1) and that worked a treat thanks. So with this I am using my original formula:

    =SMALL(A1:A9,COUNTIF(A1:A9,"<"&A11)+1)

    How can I ignore the time value 0 or 00:00:00??

  13. #13
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    Also, if I use the same formula to find the largest time value in the range (range has no 00:00:00 values) it still gives me the smallest time value in the range.

    =LARGE(A1:A9,COUNTIF(A1:A9,"<"&A11)+1)

    =LARGE(A1:A9,1) gives me the largest time value but when I add the countif component it only gives me the smallest???

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Smallest value in range above criteria

    Unless all your times are 0 or they are less than the time in A11, then you should always get a result or you will get an error....

    Can you show an example of what you mean?

  15. #15
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    Sure, range in A1:A9 is the following:
    15:01:10; 15:01:12; 15:01:13; 15:01:15; 15:01:16; 15:01:17; 15:01:21; 15:01:22; 15:01:23;
    Cell A11 is 15:01:14

    Using =SMALL(A1:A9,COUNTIF(A1:A9,"<"&A11)+1) I get 15:01:15 which is correct

    Using =LARGE(A1:A9,COUNTIF(A1:A9,"<"&A11)+1) I get 15:01:10 when I should get the largest in the range > A11, which should be 15:01:23

  16. #16
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Smallest value in range above criteria

    with Large, it doesn't work the same way, that is why I liked my original suggestion of

    =MIN(IF(A1:A9>=A11,A1:A9))

    and now for largest

    =MAX(IF(A1:A9>=A11,A1:A9))

    both confirmed with CTRL+SHIFT+ENTER

  17. #17
    Registered User
    Join Date
    03-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Smallest value in range above criteria

    That worked nicely, thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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