View Full Version : A code to show colour in cell from list
rodneykaye
10-16-2013, 07:20 PM
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
Rick Rothstein
10-16-2013, 07:47 PM
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.
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.
rodneykaye
10-17-2013, 04:06 AM
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
Rick Rothstein
10-17-2013, 04:36 AM
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...
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.
rodneykaye
10-18-2013, 03:56 PM
Thank you Rick
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.