+ Reply to Thread
Results 1 to 7 of 7

If TIME falls between these bounds, label it X, etc.

  1. #1
    Forum Contributor
    Join Date
    02-15-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    141

    If TIME falls between these bounds, label it X, etc.

    I have a massive spreadsheet with start and end times in columns A and B. I'd like to add a third column that shows a label for that time period.

    For instance, any items between 8AM and 3PM would be called "X", and any items between 3PM and 6PM would be called "Y", etc. I could probably write a lengthy =IF formula, but I'm wondering if there's a more efficient way to do this. Maybe some sort of reference table and a VLookup?

    Here's an example of what I'm trying to accomplish.

    Excel Example - Add Labels.xlsx

  2. #2
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: If TIME falls between these bounds, label it X, etc.

    This is based on the end time and not the start time so any time that crosses the boundary is counted as the end time. Enter in column C and copy down.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,669

    Re: If TIME falls between these bounds, label it X, etc.

    Your last example shows overlap and you want to match it to the "closest" fit. How do you define the closest fit?

    Because your times ranges in the table to the right are more or less mutually exclusive and collectively exhaustive you could do this for a single value with a VLOOKUP but doing it for a time range gets complicated without very explicit requirements for overlap. The formula gets complicated because then you have to evaluate how much overlap there is in each interval and choose the one with the most overlap. And suppose you have overlap across more than two intervals?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    02-15-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: If TIME falls between these bounds, label it X, etc.

    For overlap I'm thinking the label should be assigned based on how many hours it has in each interval. So 2 to 6 has 3 hours in Y and only 1 hour in X, therefore I would call it Y.

  5. #5
    Forum Contributor
    Join Date
    02-15-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: If TIME falls between these bounds, label it X, etc.

    Is that possible (regarding overlap)?

  6. #6
    Forum Contributor
    Join Date
    02-15-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: If TIME falls between these bounds, label it X, etc.

    Nevermind, I was able to break out the data in finer detail so that there are no longer overlaps. Thanks!

    Now, returning to my original question...are IF statements the best/easiest way to do this?

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,669

    Re: If TIME falls between these bounds, label it X, etc.

    Yes, you have to use IF statements in some form to do this, because you have to check for certain conditions and provide different results based on those conditions. The alternative to using formulas would be to use VBA macros.

+ 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. [SOLVED] Find row where time value falls between start and end time values
    By wraithlet in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-12-2013, 12:35 PM
  2. [SOLVED] VBA to calculate the amount of time that falls between the time recorded in two cells.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2012, 02:39 PM
  3. Replies: 3
    Last Post: 05-25-2012, 03:41 PM
  4. Determining if date/time falls within spanned time
    By Bytor47 in forum Excel General
    Replies: 5
    Last Post: 09-15-2009, 01:55 PM
  5. Replies: 1
    Last Post: 03-19-2007, 07:53 AM

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