Results 1 to 5 of 5

Thread: A code to show colour in cell from list

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    A code to show colour in cell from list

    Can a code be supplied where i have a group of dropdown lists of colours.When a coloir is selected in any or all these cells it colours the cell whatever colour is selected.If i select Blue from the list then it colours the cell Blue

    Regards

    RK
    Attached Files Attached Files

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by rodneykaye View Post
    Can a code be supplied where i have a group of dropdown lists of colours.When a coloir is selected in any or all these cells it colours the cell whatever colour is selected.If i select Blue from the list then it colours the cell Blue
    You can use the following event code to do that. One thing to point out to you, though... your drop down list has a blank space following the "E" in "BLUE" which is why my code below has a blank space following the "E" in "BLUE" as well. If you choose to correct your list by removing that space character, then remember to do that in the code below as well.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Count > 1 Then Exit Sub
      If Not Intersect(Target, Range("C3,E3,G3,I3,C9,E9,G9,I9,C15,E15,G15,I15")) Is Nothing Then
        Select Case Target.Value
          Case "RED": Target.Interior.ColorIndex = 3
          Case "BLUE ": Target.Interior.ColorIndex = 5
          Case "GREEN": Target.Interior.ColorIndex = 4
          Case "YELLOW": Target.Interior.ColorIndex = 6
          Case "WHITE": Target.Interior.ColorIndex = 2
        End Select
      End If
    End Sub
    HOW TO INSTALL Event Code
    ------------------------------------
    If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0
    Thank you Rick

    This works just fine.Can it work without the word of the colour being visible.Just want the colour to be available

    Regards

    RK
    Attached Files Attached Files

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by rodneykaye View Post
    Thank you Rick

    This works just fine.Can it work without the word of the colour being visible.Just want the colour to be available
    I guess the easiest way is to make the font color the same as the background color...

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Count > 1 Then Exit Sub
      If Not Intersect(Target, Range("C3,E3,G3,I3,C9,E9,G9,I9,C15,E15,G15,I15")) Is Nothing Then
        Select Case Target.Value
          Case "RED": Target.Interior.ColorIndex = 3
          Case "BLUE ": Target.Interior.ColorIndex = 5
          Case "GREEN": Target.Interior.ColorIndex = 4
          Case "YELLOW": Target.Interior.ColorIndex = 6
          Case "WHITE": Target.Interior.ColorIndex = 2
        End Select
        Target.Font.ColorIndex = Target.Interior.ColorIndex
      End If
    End Sub
    I highlighted the line of code I added to do this so you can see how it is done.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0
    Thank you Rick

Similar Threads

  1. Replies: 14
    Last Post: 10-23-2013, 01:24 PM
  2. Replies: 0
    Last Post: 09-27-2013, 11:33 AM
  3. Replies: 4
    Last Post: 07-27-2013, 01:34 PM
  4. VBA code to delete cell ranges
    By rich_cirillo in forum Excel Help
    Replies: 3
    Last Post: 07-08-2013, 09:18 AM
  5. Import html source of url list in each cell
    By Sergio Alfaro Lloret in forum Excel Help
    Replies: 8
    Last Post: 07-31-2012, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •