+ Reply to Thread
Results 1 to 3 of 3

Format cell color on change, how to change the color in other columns as well?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-14-2006
    Location
    Netherlands
    MS-Off Ver
    2000, 2003, and 2007
    Posts
    32

    Format cell color on change, how to change the color in other columns as well?

    Currently I've got the following (found) piece of code which colors the cell on row E on changing the value.

    Which adjustments need to be made to the code in order to make it color other cells on the same row as well (e.g. columns A to C and H)?

    Cheers for all your help in advance!

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    ' Conditional Formatting for more than 3 conditions
    
        Dim rng As Range
    
        Set rng = Intersect(Target, Range("E:E"))
        If rng Is Nothing Then
            Exit Sub
        Else
            Dim c As Range
            For Each c In rng
                Select Case c.Text
                Case "Upcoming"
                    c.Interior.ColorIndex = 34
                Case "Open"
                    c.Interior.ColorIndex = xlNone
                Case "Pending"
                    c.Interior.ColorIndex = 22
                Case "On Hold"
                    c.Interior.ColorIndex = 22
                Case "Finished"
                    c.Interior.ColorIndex = xlNone
                Case "Cancelled"
                    c.Interior.ColorIndex = 3
                Case "Order Hardware"
                    c.Interior.ColorIndex = 44
                Case "Awaiting Order"
                    c.Interior.ColorIndex = 45
                Case "SPECIAL"
                    c.Interior.ColorIndex = 43
                Case "R&M initiated"
                    c.Interior.ColorIndex = 43
                Case Else
                    c.Interior.ColorIndex = xlNone
                    Exit Sub
                End Select
            Next c
        End If
    
    End Sub
    Life's a canvas, you fill the picture!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Perhaps this:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng     As Excel.Range
        Dim cell    As Excel.Range
        Dim iCI     As Long
    
        Set rng = Intersect(Target, Columns("E"))
        If rng Is Nothing Then
            Exit Sub
        Else
            For Each cell In rng
                Select Case cell.Text
                    Case "Upcoming":       iCI = 34
                    Case "Open":           iCI = xlNone
                    Case "Pending":        iCI = 22
                    Case "On Hold":        iCI = 22
                    Case "Finished":       iCI = xlNone
                    Case "Cancelled":      iCI = 3
                    Case "Order Hardware": iCI = 44
                    Case "Awaiting Order": iCI = 45
                    Case "SPECIAL":        iCI = 43
                    Case "R&M initiated":  iCI = 43
                    Case Else:             iCI = xlNone
                End Select
                Set cell = Intersect(cell.EntireRow, Union(Columns("A:C"), Columns("H")))
                cell.Interior.ColorIndex = iCI
            Next cell
        End If
    End Sub

  3. #3
    Registered User
    Join Date
    07-14-2006
    Location
    Netherlands
    MS-Off Ver
    2000, 2003, and 2007
    Posts
    32
    Cheers, this works like a charm

+ 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