+ Reply to Thread
Results 1 to 18 of 18

Change font color based on the ending text string (date) of a cell

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Change font color based on the ending text string (date) of a cell

    Hello!

    I have a range from Cells B2:E5. Within each cell, there is a text string with a bullet point. At the end of each text string, there is a date in the format (mm/dd) and the text string also includes these parenthesis. The text string will also sometimes either include the words "Green*", "Yellow*", or "Red*", AFTER the date or the text string could not contain any of these. However, if the text string does contain one of these words it will ONLY be one of them never two. What I want the macro to do is the following:

    - If the string DOES NOT include (Green*, Yellow*, Red*), then I want this text to be GREY.
    - If the string CONTAINS any kind of (Green*, Yellow*, Red*) AND the date within the string is today or prior, then I want this text to be RED.
    - If the string CONTAINS any kind of (Green*, Yellow*, Red*) AND the date within the string is AFTER today (in the future), then I want this text to be BLACK.


    However, there is a catch. Even though the text string can contain the words ("Green*", "Yellow*", or "Red*") I want every single one of these text string to remain their color in nature. Meaning even though the text string qualifies for a certain parameter for the string to be GREY I still want the text string that contains "Green*" to be the color green, and so on for Yellow or Red.

    Please see the example workbook attached.
    Attached Files Attached Files

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Hi Brian,

    fun assignment!

    I think the code below does what you want it to do.

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  3. #3
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    Hey Ollie,

    Once again, your code worked beautifully within the example workbook . When I transferred the code to the target workbook, I received a "Type Mismatch" runtime error at the following code line (line 75):

    datTargetDate = DateSerial(Year(Now()), CInt(Mid$(varBulletLine, intBracketFound + 1, 2)), CInt(Mid$(varBulletLine, intBracketFound + 4, 2)))

    The only part of the code I edited was the Sheet name "CommSlide" and the range "D2:Z113"

    Any thoughts?

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    It probably encountered (../..) in the text but the first part is not a valid value for the month or the second part is not a valid value for day.

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    We can probably enhance the error checking for this part. Will have a look tomorrow

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Hi Brian,

    Enhanced processing for finding a date in the text string

    Please Login or Register  to view this content.
    Last edited by OllieB; 01-18-2013 at 02:31 AM. Reason: highlighted the changes made in blue

  7. #7
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    Hey Ollie,

    The coding is almost there... A few things I see that need to be fixed:

    - Some text strings will have a range of dates (01/18-02/22)
    * If this happens, and taking into account the parameters mentioned before:
    1) If the string DOES NOT include (Green*, Yellow*, Red*), then I want this text to be GREY.
    2) If the string CONTAINS any kind of (Green*, Yellow*, Red*) AND the date within the string is today or prior, then I want this text to be RED.
    3) If the string CONTAINS any kind of (Green*, Yellow*, Red*) AND the date within the string is AFTER today (in the future), then I want this text to be BLACK.

    * Then this text string is actually considered on-time (so should be black font) since the 2/22 is in the future and is after today's date.
    * So, if the text string contains a date RANGE, use the END of the date range for the parameter.
    ** Currently the VBA doesn't take this into account, I believe your coding is looking at the 1st date, I aplogize as I failed to mention this earlier.

    - Some of the text that contains the words, "Green*", "Yellow*", and "Red*" didn't maintain their color and are black. Not sure why..but there are lots of them that didnt maintain their true color in nature.
    * I thought this might've been happening for all of the text that met the 3rd parameter, but this doesn't seem to be the case:
    - For the text strings that meet the 3rd parameter, there are some text strings that kept the Green, Yellow, or Red color and then some that didn't. However, I don't see a pattern for this error.

    - For the 1st parameter, I don't see any errors and this seems to be working exactly as it should.

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Please post a copy of your workbook so I can check what is happening and make the necessary corrections.

  9. #9
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    I have made the example workbook much more similar to how the actual workbook looks like. This is about the range I work with. Instead of the words ("Green*", "Yellow*", and "Red*") maintaining their current color, lets add some code that just changes these words font color to their color in nature every time so there is never one that is missed.

    Please let me know if you have any questions or concerns
    Attached Files Attached Files

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Hi Brian,

    It took a bit of work to make the date recognition work properly. I have changed the assignment of colors to the various text words, but could not find any errors in that bit of code. I think it works but please run some tests yourself as well
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    I transfered to Target Workbook, subscript out of range line 113 in code:

    strMonthPart = Trim$(Split(Split(strDatePart, "-")(1), "/")(0))

  12. #12
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Brian,

    This is going to be though. The tool now supports
    a. ignore a "(..)" of less than 5 characters in length;
    b. accept (mm/d)
    c. accept (mm/dd - mm/dd)
    d. accept (mm/dd-mm/dd)
    etc etc

    Check the cell.address of the cell that is causing the error and let me know the contents. The problem is probably the occurrence of (....) with text values as opposed to a date.

  13. #13
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    Okay. What is the code that I need to put before or after the code where I am receiving the error?

  14. #14
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    When the error occurs hover your cursor over rngCell.Address in the code to see the address of the cell in error

  15. #15
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    Hey Ollie,

    Sorry I haven't responded..I have been out of town for the holiday weekend, but now back to work and hitting the ground running!

    So I took a look at thet code and at the point where it errored out. I checked the cell that was giving the error. It appears that in one of the text strings, there are 2 different instances of the parenthesis. In this cell, the string reads like this:

    • String has the following values in parenthesis (Infrastructure Deadline) (01/18) *Green

    There is a step within my process within extracting the data that I believe I can get rid of the first set of parenthesis. I'll let you know what happens!

  16. #16
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Hi Brian, any update on the status of this thread?

  17. #17
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Change font color based on the ending text string (date) of a cell

    Hey Ollie!

    You are right it has been awhile...I do apologize. I haven't been able to fix the error. But my boss asked me to work on a different assignment so I have somewhat put this on the back burner. I think it is an easy fix, I just have to find the time to find a work around. Can we keep this open for the mean time?

    Brian

  18. #18
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Change font color based on the ending text string (date) of a cell

    Sure, no problem

+ 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