Time in Excel

Discussion in 'Software' started by generalgort, Apr 22, 2010.

  1. generalgort

    generalgort Private E-2

    Hi Guys,

    In Excel I want to write a formula involving times for conditional formatting, what I need is:

    If B6 has a value > 7:00am AND < 10:00am, OR B6 has a value > 1:00pm AND < 3:00pm then F6 is coloured Green, if not F6 is coloured Red.

    I have tried the 'Insert Function' but all I managed to get is more confused.

    Appreciate any help,

    Phil
     
  2. usafveteran

    usafveteran MajorGeek

    What version of Excel are you using?
     
  3. generalgort

    generalgort Private E-2

    Hi Usafveteran,

    I am using 2002 with SP3,

    Phil.
     
  4. Gabethebabe

    Gabethebabe Private E-2

    Code:
    OR(AND((HOUR(B6)>6);(HOUR(B6)<10));AND((HOUR(B6)>12);(HOUR(B6)<15)))
    This formula is TRUE 07:00-09:59:99 and 13:00-14:59:59

    Use conditional formatting of F6.

    Hope this helps.
     
  5. generalgort

    generalgort Private E-2

    Hi Gabethebabe,

    Thanks for the formula, I am supposed to put this into the cell arn't I? I can't get it to work, every time I put it into the cell, preceded with '=' it comes up with 'Invalid' for : '(HOUR(B6)>6);(HOUR(B6)<10)'.

    I have rechecked that I have inserted it correctly, the times in B6 are not whole hours, but hours and minutes, I am entering as 07:15 etc.
     
    Last edited: Apr 22, 2010
  6. GCWesq

    GCWesq MajorGeek

    I think you just need to change the punctuation:
    =OR(AND((HOUR(B6)>6),(HOUR(B6)<10)),AND((HOUR(B6)>12),(HOUR(B6)<15)))
     
  7. generalgort

    generalgort Private E-2

    Thanks GCWesq,

    That's sorted it out.
     
  8. usafveteran

    usafveteran MajorGeek

    Now, you just need to add the conditional formatting, right?
     
  9. generalgort

    generalgort Private E-2

    Hi Guys,

    Me again, that formula worked great, but it does mean that the column is coloured when there is no data in B6, well I tried modifying it so that the column is not coloured until there is data in B6:

    =IF(B6="",(OR(AND((HOUR(B6)>6),(HOUR(B6)<10)),AND((HOUR(B6)>12),(HOUR(B6)<15)))),0)

    Can you guys tell me why this doesn't work please, and what I need to do to make it work,

    Thanks.
     
  10. GCWesq

    GCWesq MajorGeek

    You need two separate formulae (each condition can only have a True or False value).
    Keep the original formula in your first condition:

    =OR(AND((HOUR(B6)>6),(HOUR(B6)<10)),AND((HOUR(B6)>12),(HOUR(B6)<15)))

    Click on Add in the Conditional Formatting panel, and put the following under Condition 2 (using Formula Is... again):

    =B6<>""

    Give this the fill colour you want when the cell has a value, but it's outside the times you specified.
     
  11. generalgort

    generalgort Private E-2

    Thanks GCWesq,

    I have now learnt something else about Excel, I didn't realise you could use Conditional Formating with the formulas like that.

    Works a treat!
     
  12. GCWesq

    GCWesq MajorGeek

    Excellent! :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds