+ Reply to Thread
Results 1 to 14 of 14

Set background color based on cell value

Hybrid View

  1. #1
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Set background color based on cell value

    Quote Originally Posted by tgal View Post
    Hi, I have but my managers have the ability to **** up just about everything , that's why I want to use VBA.
    Thanks,
    Thomas
    From this I take it he wants to cover just about every eventuality

    I just don't see the point on limiting the code to working on one cell (at least without warning the user that they should only change one cell if they do change more) when a range can be handled quite easily.

    I used to limit change events to working on one cell but personally think this is a better approach.

    Dom
    Last edited by Domski; 04-28-2011 at 10:29 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Set background color based on cell value

    In that case I'd prefer:

    Private Sub Worksheet_Change(ByVal Target As Range)
      If Intersect(Target, Range("A1:A10")) Is Nothing Then Exit Sub
      For Each cl In Intersect(Target, Range("A1:A10"))
        With cl.Interior
          .ColorIndex = xlNone
          If cl > 0 And cl < 6 Then .ColorIndex = Choose(cl, 27, 3, 4, 32, 46)
          Sheets("Sheet2").Range(cl.Address).Interior.ColorIndex = .ColorIndex
        End With
      Next
    End Sub



+ 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