+ Reply to Thread
Results 1 to 9 of 9

Identify if a date falls between one or more intervals in an array, and highlight cell so.

  1. #1
    Registered User
    Join Date
    09-24-2020
    Location
    Denmark
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Identify if a date falls between one or more intervals in an array, and highlight cell so.

    See attached spreadsheet.

    My goal is to identify if the date in B9 falls between any of the intervals in B17:C23.

    My first step was to work with an array function. It works nicely in D17:D23. But the same formula does not work in E17:E23.
    Question 1: Can anyone explain me why D17:D23 produce the right result and E17:E23 does not?

    My goal is to highlight B9, if the date I enter falls between any of the intervals in B17:C23. If I had succeded in understanding the mechanics to question 1, I was planning to use a similar function in 'Conditional Formatting'.
    Question 2: What function should I put into the 'Conditional Formatting' for B9, so that the field is highlighted, if the date falls between one or more intervals in D17:C23?
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Hi,

    The reason is that you have committed the formula in column D as a multi-cell array formula (i.e. by first selecting the multi-cell range D17:D23 and then committing the formula with CTRL+SHIFT+ENTER), whereas you have committed the formula in column E as a single-cell array formula (i.e. by first selecting the single-cell range E17, then committing the formula with CTRL+SHIFT+ENTER, then copying down to cell E23).

    A multi-cell array formula operates in a row-relative manner, meaning that each instance of the formula processes the row from the range passed according to its position within the multi-cell range to which the formula has been committed. So the result in cell D20 is evaluating the formula with respect to the entries in B20 and C20. Note that the first cell within the range for the multi-cell array formula does not have to be the same as the first cell containing the results: you could cut your present multi-cell array formula and paste it into any range you like, for example G21:G27, and it would still give the same results.

    A single-cell array formula, such as the one you have here, will only ever process the first entry in the resulting array derived from your conditions, since that array is not being passed to any further indexing function.

    Regards
    Last edited by XOR LX; 09-24-2020 at 09:17 AM.
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    you can do it through the interface, like doing this multiple times:
    Attached Images Attached Images

  4. #4
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,781

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Conditional Formatting

    =SUMPRODUCT(($B$9>=B17)*($B$9<=C17))>0


    Applies to =$B$17:$C$23

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Not sure why you have chosen to use an Array Function, other than you can. A simple:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down would give the same result. And I'd guess there's less of a performance hit. But, your choice.

    For the Conditional Formatting, you could use the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Registered User
    Join Date
    09-24-2020
    Location
    Denmark
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Quote Originally Posted by XOR LX View Post
    Hi,

    The reason is that you have committed the formula in column D as a multi-cell array formula (i.e. by first selecting the multi-cell range D17:D23 and then committing the formula with CTRL+SHIFT+ENTER), whereas you have committed the formula in column E as a single-cell array formula (i.e. by first selecting the single-cell range E17, then committing the formula with CTRL+SHIFT+ENTER, then copying down to cell E23).

    A multi-cell array formula operates in a row-relative manner, meaning that each instance of the formula processes the row from the range passed according to its position within the multi-cell range to which the formula has been committed. So the result in cell D20 is evaluating the formula with respect to the entries in B20 and C20. Note that the first cell within the range for the multi-cell array formula does not have to be the same as the first cell containing the results: you could cut your present multi-cell array formula and paste it into any range you like, for example G21:G27, and it would still give the same results.

    A single-cell array formula, such as the one you have here, will only ever process the first entry in the resulting array derived from your conditions, since that array is not being passed to any further indexing function.

    Regards
    Thanks a lot for this answer to question 1. Now I understand. :-)

  7. #7
    Registered User
    Join Date
    09-24-2020
    Location
    Denmark
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Quote Originally Posted by vba_php View Post
    you can do it through the interface, like doing this multiple times:
    Thanks. Yep. That works. I was hoping to put in a formula in just one rule and thereby avoid multiple rules.

    Cheers

  8. #8
    Registered User
    Join Date
    09-24-2020
    Location
    Denmark
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Quote Originally Posted by CARACALLA View Post
    Conditional Formatting

    =SUMPRODUCT(($B$9>=B17)*($B$9<=C17))>0


    Applies to =$B$17:$C$23
    Thanks. With this approach the date intervals will be highlighted. I am looking for a way to highlight B9 only.

    Cheers.

  9. #9
    Registered User
    Join Date
    09-24-2020
    Location
    Denmark
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: Identify if a date falls between one or more intervals in an array, and highlight cell

    Quote Originally Posted by TMS View Post
    Not sure why you have chosen to use an Array Function, other than you can. A simple:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down would give the same result. And I'd guess there's less of a performance hit. But, your choice.

    For the Conditional Formatting, you could use the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    My bad. It was unclear. Column D and E are only there to illustrate how the same formula behaves differently. And now I understand why from the answer from XOR XL. Column D and E will not be there in the final version and I will not be able to search for the word 'MATCH!'.

    Cheers

+ 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] Identify if date falls within a date range
    By Chris F in forum Excel - New Users/Basics
    Replies: 14
    Last Post: 02-23-2022, 08:40 AM
  2. Replies: 2
    Last Post: 04-26-2017, 08:06 AM
  3. Highlight whole row if date falls on a Sunday / Add Year
    By bgalarneau in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-03-2015, 05:01 PM
  4. Identify first cell in range whose value falls X units below previous max?
    By hadamhiram in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 03-27-2013, 09:01 PM
  5. [SOLVED] Scan a series of rows in sequence and identify cell where value falls below previous max?
    By hadamhiram in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2013, 03:31 AM
  6. Replies: 4
    Last Post: 04-13-2011, 06:26 AM
  7. Replies: 1
    Last Post: 07-19-2006, 09:40 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