+ Reply to Thread
Results 1 to 6 of 6

VBA Macro to Color Row Text If Date in Cell is greater than system date

Hybrid View

slick9456 VBA Macro to Color Row Text... 09-24-2014, 04:54 PM
judgeh59 Re: VBA Macro to Color Row... 09-24-2014, 05:07 PM
judgeh59 Re: VBA Macro to Color Row... 09-24-2014, 05:09 PM
slick9456 Re: VBA Macro to Color Row... 09-24-2014, 05:33 PM
judgeh59 Re: VBA Macro to Color Row... 09-24-2014, 05:39 PM
slick9456 Re: VBA Macro to Color Row... 09-24-2014, 06:09 PM
  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    VBA Macro to Color Row Text If Date in Cell is greater than system date

    Hoping someone can help me here, as this is uncharted territory for me.

    I am hoping to write a Macro that checks If the date in any cell in column U is 6 months greater than the system date, it will color the entire row's text red.

    I found this tidbit out there, and was hoping someone can skillfully re-purpose it to do what I described above. From what I saw this may be the answer to what I was looking for but I am not yet skillful enough to do this myself.

    The Assumptions for this sample was:

    If the date in column H matches the system date, then those rows will become green.
    If the date in column H is the next date (tomorrow), those rows will become yellow.
    If the date in column H is 2 to 6 days out, those rows will become blue.
    If the date in column H is 7 to 13 days out, those rows will become orange.
    If the date in column H is 14 to 20 days out, those rows will become red.
    If the date in column H is 21 to 27 days out, those rows will become tan.
    If the date in column H is equal to or greater than 28 days out, those rows will remain white.

    Sub test2()
    Dim LR As Long, i As Long
    LR = Range("U" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        With Range("U" & i)
            Select Case .Value - Date
                Case 0: .EntireRow.Interior.ColorIndex = 4
                Case 1: .EntireRow.Interior.ColorIndex = 6
                Case 2 To 6: .EntireRow.Interior.ColorIndex = 5
                Case 7 To 13: .EntireRow.Interior.ColorIndex = 45
                Case 14 To 20: .EntireRow.Interior.ColorIndex = 3
                Case 21 To 27: .EntireRow.Interior.ColorIndex = 53
           End Select
        End With
    Next i
    End Sub
    I hope what I'm looking for is somewhere in there, but if not I am open to suggestions on other methods to research.

    Thanks!

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: VBA Macro to Color Row Text If Date in Cell is greater than system date

    I Deleted it
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: VBA Macro to Color Row Text If Date in Cell is greater than system date

    I tried this and it worked....are you using real XL dates on your worksheet?

  4. #4
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: VBA Macro to Color Row Text If Date in Cell is greater than system date

    Sorry, to clarify, the code above was from an example I pulled that I thought might be close to what I needed, I may be completely wrong...

    The dates in my spreadsheet in column U are in the date format seen in the image below.

    Hopefully this clarifies, but again I only need one scenario which is to check the date in each cell in column U, if it's more than 6 months greater than the system date, color the row red text.

    Date Image.jpg

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: VBA Macro to Color Row Text If Date in Cell is greater than system date

    oh!

    Sub test2()
    
        Dim LR As Long, i As Long
        
        LR = Range("U" & Rows.Count).End(xlUp).Row
        
        For i = 2 To LR
            With Range("U" & i)
                Select Case .Value - Date
                    Case Is > 180
                        .EntireRow.Interior.ColorIndex = 3
                End Select
            End With
        Next i
    
    End Sub
    You can also do this with conditional formatting....

  6. #6
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: VBA Macro to Color Row Text If Date in Cell is greater than system date

    Judge thank you so much. This was a huge help. Again, VBA was needed versus conditional formatting because of the way the data gets exported from a central system.

    I tweaked yours slightly so that it colors the text red versus changing the fill color. And had to change the variable as I already had one for "i" defined earlier on in the larger macro.

        Dim LR As Long, P As Long
        
        LR = Range("U" & Rows.Count).End(xlUp).Row
        
        For P = 2 To LR
            With Range("U" & P)
                Select Case .Value - Date
                    Case Is > 180
                        .EntireRow.Font.Color = RGB(255, 0, 0)
                End Select
            End With
        Next P

+ 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. Replies: 7
    Last Post: 10-02-2017, 12:09 PM
  2. Macro to Change color of cell after cross referencing date with a given date.
    By liajet24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2013, 12:33 PM
  3. Replies: 5
    Last Post: 07-03-2012, 01:23 PM
  4. How to compare system date with the date in cell of a ws?
    By techissue2008 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-23-2009, 01:10 PM
  5. RE: Color cell text based on date
    By Gary''s Student in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-09-2005, 08:40 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