+ Reply to Thread
Results 1 to 11 of 11

How Do I Write a Macro for Highlighting Rows Based on Date Criteria

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    I need my spreadsheet to perform the following:

    -If today's date is later than the date in column E and there are no dates in columns F-J, Highlight the row orange until a date is filled in to either of those columns.

    -If today's date is two or more days later than the date in column F and there is no date in column G-J, highlight the row light blue until a date is filled in to either of those columns.

    -If today's date is later than the date in column G and there is no date in column H or J, highlight the row yellow until a date is filed in to column H or J.

    I was able to figure out how to perform the first bullet using conditional formatting using the following:
    =IF(ISBLANK($E157),"",(IF($E157<TODAY(), (AND(ISBLANK(F157),ISBLANK(G157),ISBLANK(H157),ISBLANK(I),ISBLANK(J157),(IF(ISBLANK($F157),"",(IF($F157<=TODAY()+2, (AND(ISBLANK(G157),ISBLANK(H157),ISBLANK(I157),ISBLANK(J157))))))))))))

    I couldn't get any of the other rules to work and was told that I may have to use Macros. I have no experience creating Macros and have tried multiple avenues for help on the internet and within Excel.

    I am hoping that someone will be able to help me in this forum.

    Thanks in advance
    Tara

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Most CF formulas don't need to be IF tests, you simply test the criteria and without the IF the result will return TRUE/FALSE by design. To understand this, put this formulae in some cells:

    =1=1 (should show TRUE)
    =2>3 (should show FALSE)

    Now just do that same thing with your more complex tests.


    RED Rule #1:
    =AND(TODAY()>$E157, $E157>0, COUNT($F157,$J157)=0)

    BLUE Rule #2:
    =AND(TODAY()-$F157>1, $F157>0, COUNT($G157,$J157)=0)

    YELLOW Rule #3
    =AND(TODAY()-$G157>1, $G157>0, COUNT($H157,$J157)=0)


    NOTE: That's 3 CF rules, that's all you get in one cell in Excel 2003. You should be upgrading soon, yes?
    Last edited by JBeaucaire; 02-18-2013 at 12:30 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Thank you for your help. I'll try this to see if I can get it to work. I also did not mean to enter 2003. It should be 2007. How big of a difference will that make?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    In 2003 you only get 3 CF formulas in a single cell. That limitation doesn't exist in 2007+, you can add as you need.

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

  5. #5
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Quote Originally Posted by JBeaucaire View Post
    In 2003 you only get 3 CF formulas in a single cell. That limitation doesn't exist in 2007+, you can add as you need.

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

    That worked. Thank you so much for your help. I am so glad that it did not require macros as I was told.

    I appreciate the time you took to help me with this!

    Tara

  6. #6
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Quote Originally Posted by JBeaucaire View Post
    Most CF formulas don't need to be IF tests, you simply test the criteria and without the IF the result will return TRUE/FALSE by design. To understand this, put this formulae in some cells:

    =1=1 (should show TRUE)
    =2>3 (should show FALSE)

    Now just do that same thing with your more complex tests.


    RED Rule #1:
    =AND(TODAY()>$E157, $E157>0, COUNT($F157,$J157)=0)

    BLUE Rule #2:
    =AND(TODAY()-$F157>1, $F157>0, COUNT($G157,$J157)=0)

    YELLOW Rule #3
    =AND(TODAY()-$G157>1, $G157>0, COUNT($H157,$J157)=0)


    NOTE: That's 3 CF rules, that's all you get in one cell in Excel 2003. You should be upgrading soon, yes?

    JBeaucaire,

    Once I applied the rules to my full spreadsheet they no longer worked properly. There are rows highlighted that should not be, and ones that won't unhighlight if you add a date into one of the later columns.

    I'm not sure why it seemed to work so well when I just applied it to the last 10 rows of my spreadsheet.

    What could I be doing wrong? I have attached my spreadsheet.

    Thank you for your help.
    Attached Files Attached Files

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Example rows you want checked?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Hm, I found a few, yes, you're right, the CF rules when put in CELLS are giving FALSE results, but in the CF are triggering TRUE/colors. No clue why.

  9. #9
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Quote Originally Posted by JBeaucaire View Post
    Example rows you want checked?
    Examples:
    Row 25 is Yellow and should be Blue.

    Rows 27,41,46,51 are examples of rows that are still orange (RULE #1 says RED), but should be blank since there are dates in the later columns.

    Row 28 Should be Yellow, but it's blank

    Rows 36,66,70 are examples of rows that should be Orange

    Row 73 should no longer be Blue



    I am at a loss as to why it worked when my cell range was A157:J168. I used just a small section so I wouldn't mess up my spreadsheet while I played around with getting it to work.

  10. #10
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    I'll have to go back and see why it works on the smaller parameter. Was thinking about opening a new sheet, entering in the CF's and my date formula. Then, copy and paste in the data and see if it works that way. I haven't done anything different from when it was working on my smaller range of rows

    I'll get back on it tomorrow. Too frustrated with it :-)

  11. #11
    Registered User
    Join Date
    02-17-2013
    Location
    Raleigh, North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How Do I Write a Macro for Highlighting Rows Based on Date Criteria

    Well it looks like it was an issue with the different versions of Excel and what version it was saved in. When simply saved as an excel workbook, it was fine. If you try to save it as a specific version of excel there is an issue with the formatting, and it no longer works properly.

    I changed one thing with the conditional formatting rules that you provided which made it work as needed:

    =AND(TODAY()>$E2,$E2>0,COUNT($F2:$J2)=0)

    Adding in the colon instead of a comma in the COUNT statement made the highlight function as expected when data was entered into later columns.

    The spreadsheet is up and running perfectly now. I thank you for your help on this.

    Tara

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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