+ Reply to Thread
Results 1 to 4 of 4

Thread: Change the colour of a Row when a condition changes in a cell

  1. #1
    Registered User
    Join Date
    11-02-2011
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Change the colour of a Row when a condition changes in a cell

    Hello

    I have a workbook with several sheets in Excel 2003 and was using conditional formatting to change the colour of a Row when a certain condition was met. As an example if I selected "C" from a drop down list it would change the colour of the row to orange. it worked fine but now I have more than 3 conditions so I needed some code to allow for 4 or 5 conditions.

    I found this code and adapted it for my spreadsheet but it just won't work! I have also disabled all the conditional formatting that I had in each sheet. I tried putting the code in the "workbook" and no luck so I have the code in every sheet but it still won't work. ANY help would be really appreciated.

    Private Sub Worksheet_Change(ByVal Target As Range)

    Set VacancyListOfferWoods = Range("A2:AY300")

    For Each Cell In VacancyListOfferWoods

    Select Case Cell.Value

    Case Is = "C"
    Cell.EntireRow.Interior.ColorIndex = 7

    Case Is = "F"
    Cell.EntireRow.Interior.ColorIndex = 8

    Case Is = "DB"
    Cell.EntireRow.Interior.ColorIndex = 4

    Case Is = "Q"
    Cell.EntireRow.Interior.ColorIndex = 3

    Case Else
    Cell.EntireRow.Interior.ColorIndex = xlNone

    End Select

    Next
    End Sub

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566

    Re: Change the colour of a Row when a condition changes in a cell

    Hi,

    Use the following Workbook_SheetChange event - note Workbook sheet change not Worksheet change

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
        If Not Intersect(Target, Range("A2:Ay300")) Is Nothing Then
    
            Select Case Target.Value
            Case Is = "C"
                Target.EntireRow.Interior.ColorIndex = 7
            Case Is = "F"
                Target.EntireRow.Interior.ColorIndex = 8
            Case Is = "DB"
                Target.EntireRow.Interior.ColorIndex = 4
            Case Is = "Q"
                Target.EntireRow.Interior.ColorIndex = 3
            Case Else
                Target.EntireRow.Interior.ColorIndex = xlNone
            End Select
    
        End If
    
    End Sub
    Regards
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Change the colour of a Row when a condition changes in a cell

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #4
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    Re: Change the colour of a Row when a condition changes in a cell

    Does this belong in the Access forum? Moved to Excel Programming.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0