+ Reply to Thread
Results 1 to 7 of 7

How to change the colour of so many cells in a row based on a value?

  1. #1
    Registered User
    Join Date
    03-12-2010
    Location
    Basingstoke, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    How to change the colour of so many cells in a row based on a value?

    I have this code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Set MyPlage = Range("J3:J13")
    For Each Cell In MyPlage

    If Cell.Value = "On Duty" Then
    Cell.Interior.ColorIndex = 4
    End If
    If Cell.Value = "Off Duty" Then
    Cell.Interior.ColorIndex = 3
    End If
    If Cell.Value = "Incident" Then
    Cell.Interior.ColorIndex = 3
    End If

    If Cell.Value = "Off Route" Then
    Cell.Interior.ColorIndex = 46
    End If

    If Cell.Value = "Broken Down" Then
    Cell.Interior.ColorIndex = 46
    End If

    If Cell.Value = "Welfare Break" Then
    Cell.Interior.ColorIndex = 46
    End If

    If Cell.Value = "Change Over" Then
    Cell.Interior.ColorIndex = 46
    End If

    If Cell.Value <> "On Duty" And Cell.Value <> "Off Duty" And Cell.Value <> "Incident" And Cell.Value <> "Off Route" And Cell.Value <> "Broken Down" And Cell.Value <> "Welfare Break" And Cell.Value <> "Change Over" Then
    Cell.Interior.ColorIndex = xlNone
    End If
    Next
    End Sub
    It does exactly as I want it to do, however I want cells B3 - J3 and so on down to B13 - J13 to turn a certain colour instead of just the individual cell changing. I have modified the code to "Target.EntireRow", but it's not the entire row I need. Any help would be greatly appreciated.
    Last edited by Scoodman; 10-21-2010 at 11:16 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,095

    Re: How to change the colour of so many cells in a row based on a value?

    Instead of:

    Please Login or Register  to view this content.

    Use:

    Please Login or Register  to view this content.

    and so on ...

    Regards
    Last edited by TMS; 10-21-2010 at 09:51 AM. Reason: Add Code Tags and amend code
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: How to change the colour of so many cells in a row based on a value?

    Hi Scoodman[

    I]Your post does not comply with Rule 3 of our Forum [/I]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

  4. #4
    Registered User
    Join Date
    03-12-2010
    Location
    Basingstoke, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: How to change the colour of so many cells in a row based on a value?

    Issue Solved...
    Last edited by Scoodman; 10-21-2010 at 11:15 AM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,095

    Re: How to change the colour of so many cells in a row based on a value?

    Sorry, should be:

    Please Login or Register  to view this content.

    Regards

  6. #6
    Registered User
    Join Date
    03-12-2010
    Location
    Basingstoke, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: How to change the colour of so many cells in a row based on a value?

    Perfect, thankyou very much.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,095

    Re: How to change the colour of so many cells in a row based on a value?

    You're welcome. Thanks for the feedback.

+ 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