Forum Discussion

taylorcobaugh's avatar
taylorcobaugh
Copper Contributor
Oct 07, 2020
Solved

Formula with Date Ranges

I would like for an "X" to appear in a cell when certain date ranges are entered in another cell.

 

I currently have a formula for the X to appear when the date range 10/19/2020 - 10/25/2020 is entered, but I don't know how to add multiple date ranges to the formula. The current formula I have is:
=IF(AND($BK$4>=DATEVALUE("10/19/2020"),$BK$4<=DATEVALUE("10/25/2020")),"X","")

 

I need to add a few more date ranges, one including 11/01/2020 - 11/06/2020.

  • taylorcobaugh 

     

    Try this one:

     

    =IF(OR(AND(A1>=DATEVALUE("10/19/2020"), A1<=DATEVALUE("10/25/2020")), AND(A1>=DATEVALUE("11/01/2020"), A1<=DATEVALUE("11/06/2020"))),"x","")

     

    • You may extend the formula for more dates.
    • Adjust dates & cell references in the formula as needed.

13 Replies

  • Jim-Swan's avatar
    Jim-Swan
    Copper Contributor

    taylorcobaugh 

    If i have a number, like 3 in a cell, then a want a particular formula for occur for three years, if if have a 4 in a particular cell i would like another particular formula to occur in this cell.  How do I do this?

     

    Jim

    • SergeiBaklan's avatar
      SergeiBaklan
      Diamond Contributor

      Jim-Swan 

      As variant you may use IF() or CHOOSE() or like, but depends on what exactly do you mean.

  • taylorcobaugh 

    Someone might well have suggested a table to contain the date ranges (I haven't opened all the files)

     
     

    If you wish to return IDs for the ranges then the formula extends to

     

     

    = IFERROR( 
      IF(LOOKUP(date, startRange, endRange) >= date, 
         LOOKUP(date, startRange, rangeID), 
         "-" ), 
      "-")

     

     

    replacing the "X" by a further lookup.

     

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    taylorcobaugh As a variant, have a look at the attached workbook. Include the star and end dates in two named ranges (start and end) and use a formula like:

    =IF(SUM((A10>=start)*(A10<=end)),"X","")

     where A10 holds the date you want to test. No need for nested IFS and particularly handy when you need to add more than just a few date ranges. Obviously, your dates have to be real dates, not texts looking like dates.

    • Rajesh_Sinha's avatar
      Rajesh_Sinha
      Iron Contributor
      Your formula needs little correction,,, and it must be an array (CSE) formula, need to finish with Ctrl+Shift+Enter,, otherwise you get #VALUE error !!
      • Riny_van_Eekelen's avatar
        Riny_van_Eekelen
        Platinum Contributor

        Rajesh_Sinha All depends on your Excel version. I'm on the most recent one and CSE is never an issue. It is my understanding that Excel silently converts such formulae to CSE style in older versions. But perhaps I'm mistaken. Then, indeed, such formulae should be entered with CSE.

  • Rajesh_Sinha's avatar
    Rajesh_Sinha
    Iron Contributor

    taylorcobaugh 

     

    Try this one:

     

    =IF(OR(AND(A1>=DATEVALUE("10/19/2020"), A1<=DATEVALUE("10/25/2020")), AND(A1>=DATEVALUE("11/01/2020"), A1<=DATEVALUE("11/06/2020"))),"x","")

     

    • You may extend the formula for more dates.
    • Adjust dates & cell references in the formula as needed.
    • taylorcobaugh's avatar
      taylorcobaugh
      Copper Contributor

      Rajesh_Sinha Thank you this answer did work. 

      Now I need to figure out how the formula for when multiple different date ranges produce different responses.

       

      Example:

      I want for the date range of 10/19/2020 - 10/25/2020 to produce 11 in one cell.

      And when the date range is 10/26/2020 - 11/01/2020, I want it to produce 18 in the cell.

      Then when the date range is 11/02/2020 - 11/08/2020, I want it to produce 25 in the cell.

       

      Can you help me with this?

Resources