+ Reply to Thread
Results 1 to 3 of 3

Macro to format row color in a range based on text value in column

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2012
    Location
    Barcelona, Spain
    MS-Off Ver
    2010 Professional
    Posts
    15

    Macro to format row color in a range based on text value in column

    I would like a macro to automatically (when run) color rows in a range where it begins at $A$3 to $T (the last row will change regularly) based on a text value in column E. The two text values are "CP" and "LG" and I would like to give the "CP" row a color index of 35 and the "LG" rows a color index of 37. I would only like the row to be colored up to the last column in the range "T". Thanks in advance.

  2. #2
    Registered User
    Join Date
    02-16-2012
    Location
    Barcelona, Spain
    MS-Off Ver
    2010 Professional
    Posts
    15

    Re: Macro to format row color in a range based on text value in column

    I've managed to do it with:

    Sub test()
    Dim LR As Long, i As Long, c As Long
    LR = Range("E" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 1 To LR
        With Range("E" & i)
            Select Case .Value
                Case "CP": c = 35
                Case "LG": c = 37
                Case Else: c = xlNone
            End Select
            .Offset(, -4).Resize(, 20).Interior.ColorIndex = c
        End With
    Next i
    Application.ScreenUpdating = True
    End Sub
    However I would like to have the rows alternate between the color index and white and also avoid formatting the headings row as default which is in row 2. Any ideas?

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to format row color in a range based on text value in column

    Not sure if this is what you mean, but you just want to skip rows then change:

    For i = 1 To LR
    to

    For i = 1 To LR Step 2
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

+ 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