+ Reply to Thread
Results 1 to 9 of 9

Excel VBA change cell color if time is between

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    12

    Excel VBA change cell color if time is between

    Hello all,

    I'm attempting to change the font color on cell dependent on a time frame. The referenced cell if formatted as date.

    I can get to work if I use this:

    Please Login or Register  to view this content.
    But can't get it to work in between times:

    Please Login or Register  to view this content.
    What am I doing wrong?
    Would appreciate any help
    Thanks
    Last edited by hackini; 12-14-2016 at 12:23 PM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Excel VBA change cell color if time is between

    maybe condional formating will do the job?

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Excel VBA change cell color if time is between

    Hackini, as per forum rules, please use code tags when posting code
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Registered User
    Join Date
    01-29-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Excel VBA change cell color if time is between

    Sorry mate, totally forgot about that.

    Cheers

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Excel VBA change cell color if time is between

    Thank you for your response, I appreciate it. Found out that only colors available are vbBlack, vbWhite, vbRed, vbGreen, vbBlue, vbYellow, vbMagenta, and vbCyan.

    Cheers

  6. #6
    Registered User
    Join Date
    01-29-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Excel VBA change cell color if time is between

    Thank you for your response, I appreciate it. Found out that only colors available are vbBlack, vbWhite, vbRed, vbGreen, vbBlue, vbYellow, vbMagenta, and vbCyan.

    Cheers

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Excel VBA change cell color if time is between

    It'd be easier to see what is going on if you could provide a sample workbook... but have you checked what the value of "Cells(i, 1).Value - Int(Cells(i, 1).Value)" is when it is not working?

    After posting this I saw your follow up comments... hadn't thought of the colour not being an option... I'm glad you were able to resolve the issue.

    If orange is important you could use .ColorIndex instead of .Color... index 46 is orange. (45 is also a light orange)
    Last edited by Arkadi; 12-14-2016 at 12:36 PM.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Excel VBA change cell color if time is between

    Also, setting the .Color = RGB(255,102,0) is an orange.... there are a few values that will result in orange

  9. #9
    Registered User
    Join Date
    01-29-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Excel VBA change cell color if time is between

    The values for the times were ok but showed vbOrange=Empty, I was not getting an error with vbOrange, made some changes to "And" and "Or" and vbGreen and worked fine.
    Thanks

+ 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. Change cell color in a range of cells every time the month changes
    By Josiah in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2016, 03:15 PM
  2. Cell Color Change after time passes from a certain date
    By Ruggyz in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-26-2015, 12:28 PM
  3. [SOLVED] EXCEL NEWB.....Change cell color based on text in a cell on another sheet
    By anon1988 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-27-2014, 12:16 AM
  4. Sum numbers and change cell color each time a target total is reached
    By mike3029 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-18-2014, 02:08 AM
  5. color change of excel cell.
    By sanjayaexcel in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-12-2013, 09:01 AM
  6. Excel Cell Formula to change color on a given day.
    By jamy695 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-05-2013, 08:31 AM
  7. Format cell color on change, how to change the color in other columns as well?
    By s80NL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2007, 09:24 PM

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