+ Reply to Thread
Results 1 to 11 of 11

SOLVED: Multiple opts. How returning a text value in a cell if date falls between 2 dates

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    55

    SOLVED: Multiple opts. How returning a text value in a cell if date falls between 2 dates

    Hello everyone,
    I have a cell which should return a text value (from column C in a sheet1) if in another cell a date falls between 2 dates (which ranges are in columns A and B in sheet1).
    I included an example for easy explanation!

    Thanks for your help!!!

    R
    Attached Files Attached Files
    Last edited by Rober; 05-13-2012 at 07:45 PM.

  2. #2
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    Hi Rober,

    try this one:

    Please Login or Register  to view this content.
    Please regard that the macro will fail if it finds any "non-dates" in column A, B or G. If your table contains some "header" you might want to run it only from table 2 onwards by changing
    For rNo = 1 To LastRow to For rNo = 2 To LastRow

    Regards
    Theo
    Remember To Do the Following....
    1. Upload sample files
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Valued Forum Contributor
    Join Date
    04-30-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    547

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    Hi,

    your question is not clear. The sample data is not clear. The dates in column A are later than the dates in column B. The date in column G is way outside of the date range, so it does not meet the criteria.

    Please post a sample file with data that represents what you want to achieve.

    Question: If there is more than one row that meets the criteria, which cell should be returned?

    Please upload a file that shows a better data set.

  4. #4
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    How do you say that column A is later than column B?
    Format is
    DD MONTH YY

    20-may-10 is earlier that 19-may-11
    and so on!
    10=2010
    11=2011
    12=2012

    Column A and B are ranges of dates!

    So if G2 is a date I input, the result in H2 should correspond to the column C of the ranges of dates it falls in.

    To Everyone: Can I do it with a formula instead a Macro?

    Thanks
    R

    Quote Originally Posted by npamcpp View Post
    Hi,

    your question is not clear. The sample data is not clear. The dates in column A are later than the dates in column B. The date in column G is way outside of the date range, so it does not meet the criteria.

    Please post a sample file with data that represents what you want to achieve.

    Question: If there is more than one row that meets the criteria, which cell should be returned?

    Please upload a file that shows a better data set.
    Last edited by Rober; 05-13-2012 at 02:56 PM.

  5. #5
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    Hello Rober,

    Try this with CTRL+SHIFT+ENTER, rather than just ENTER.

    Please Login or Register  to view this content.
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  6. #6
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    I can't get this to work! But it sounds promising!
    R

    Quote Originally Posted by Haseeb A View Post
    Hello Rober,

    Try this with CTRL+SHIFT+ENTER, rather than just ENTER.

    Please Login or Register  to view this content.
    Last edited by Rober; 05-13-2012 at 03:37 PM.

  7. #7
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    It is an Array formula, so must hit CTRL+SHIFT+ENTER, rather than just ENTER. If you done successfully, you can see formula surrounded by {}

    See the attached. Formula in G4
    Attached Files Attached Files

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

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    Assuming that there are no gaps between the date ranges (as per example) try

    =IF(OR(G2<A1,G2>B3),"no match",LOOKUP(G2,A1:A3,C1:C3))
    Audere est facere

  9. #9
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    I think I was able to use this, as I am testing
    View reviewed attachment!
    R
    Attached Files Attached Files

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    That will do the same thing as my LOOKUP suggestion, i.e. this formula will give the same results

    =LOOKUP(G2,B1:B3,A1:A3)

    ....but my previous suggestion also caters for dates that might be before the earliest date range or after the latest date range

  11. #11
    Registered User
    Join Date
    01-26-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: Returning a text value in a cell if date falls between 2 dates (see example included)

    Great (and yet ultrasimple) solutions.
    My question (just because I want to know how excel thinks) is how LOOKUP function can see the range???

    Thanks
    R

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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