+ Reply to Thread
Results 1 to 12 of 12

AND() function in conditional formatting

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    AND() function in conditional formatting

    Hi all,

    Trying to set up conditional formatting on a spreadsheet to fill cells based on the day of the week it is and a certain required time on that day.

    E.g. On Saturdays, the time entered must be before 7:55 to fill green.

    Any thoughts on this? any help would be appreciated

    Thanks

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: AND() function in conditional formatting

    In Conditional formatting use..

    =AND(WEEKDAY($A$1)=7,TIME($A$1)<=TIME(7,55,0)) -- fill green
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: AND() function in conditional formatting

    Hi

    =AND(WEEKDAY(A1)=7,TIME(A1)<=TIME(7,55,0))
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: AND() function in conditional formatting

    Hi,

    Thanks very much for taking the time to reply. I don't think I explained my intentions particularly well, but I've created a template spreadsheet showing what I need the conditional formatting to do. Thanks again for your time

    excel forum template.xlsx

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: AND() function in conditional formatting

    Hi,

    In which case no AND is needed if the successive days are in order, in B2 copied down

    =OFFSET(B2,7-ROW(),0)<=TIME(7,55,0)

    Note adjust the 7-ROW() bit if your data is in a row starting other than row 2

  6. #6
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: AND() function in conditional formatting

    In that case..

    =OR(AND(WEEKDAY(A2)<>7,B2<=TIME(7,25,0)),AND(WEEKDAY(A2)=7,B2<=TIME(7,55,0))) ---- fill green
    =OR(AND(WEEKDAY(A2)<>7,B2>TIME(7,25,0)),AND(WEEKDAY(A2)=7,B2>TIME(7,55,0))) --- fill red
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: AND() function in conditional formatting

    Hi again,

    Sorry, I think I'm getting a little confused now; I selected the row with the times in it and entered the formula in the conditional formatting box, but nothing seems to have changed, even after I have changed the times in some of the cells. Also, Is it possible to conditionally format based on whether the adjacent cell in the date column to the left is a saturday/week day? I ask purely because if somebody forgets to fill out one of the days, would it not throw the rest of the formula?

    Thanks again for your time and patience.

  8. #8
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: AND() function in conditional formatting

    Hi Ace_XL,

    Thanks for the reply! The formulas are partly working; there are a few issues where weekdays with times before 7:25 are being highlighted as red, and others past 7:25 are highlighted as green. Also, in the formula is (A2) a cell reference?

    Thanks

  9. #9
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: AND() function in conditional formatting

    there are a few issues where weekdays with times before 7:25 are being highlighted as red, and others past 7:25 are highlighted as green
    Not sure why. Can you post a sample?

    Also, in the formula is (A2) a cell reference?
    yes, it is a relative reference and changes based on row number, although the formula will always show A2

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

    Re: AND() function in conditional formatting

    I'd use this condition for green

    =B2<=IF(WEEKDAY(A2)=7,"7:55","7:25")+0
    Audere est facere

  11. #11
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: AND() function in conditional formatting

    Hi Daddylonglegs,

    Thanks for the reply; would you be able to break the formula down and explain the different parts for me? If I can understand it I might be able to sort a similar problem out on my own next time instead of taking up everyone's time on here.

    Thanks

  12. #12
    Registered User
    Join Date
    08-21-2012
    Location
    Letchworth, England
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: AND() function in conditional formatting

    Ace_XL,

    I've got a screenshot of the problem here;

    excel forum screenshot.jpg

+ 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