Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Andy64
 
Posts: n/a
Default How do I set a colour to 4 cells based on the value of a cell

I want to assign a colour to a group of 4 cells (ie a1 to a4) based on the
colour that is typed into another cell (ie d1). It could be that I need the
option of using 10 colours.
eg if d1 was "green" then a1-a4 would be coloured green.

  #2   Report Post  
Gord Dibben
 
Posts: n/a
Default

Andy

For greater than 3 colors(4 if use default no color) you will need VBA.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set rng1 = Intersect(Target, Range("D1"))
If rng1 Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
Set rng2 = Range("A1:A4")
'Determine the color
Select Case rng1.Value
Case Is = "green": Num = 10 'green
Case Is = "black": Num = 1 'black
Case Is = "blue": Num = 5 'blue
Case Is = "magenta": Num = 7 'magenta
Case Is = "orange": Num = 46 'orange
Case Is = "red": Num = 3 'red
'add more cases as you wish
End Select
rng2.Interior.ColorIndex = Num
endit:
Application.EnableEvents = True
End Sub

Right-click on the sheet tab and "View Code". Copy/paste the code into that
module.

Note: Data ValidationList can be used to enter the value into D1.


Gord Dibben Excel MVP


On Tue, 6 Sep 2005 09:00:22 -0700, Andy64
wrote:

I want to assign a colour to a group of 4 cells (ie a1 to a4) based on the
colour that is typed into another cell (ie d1). It could be that I need the
option of using 10 colours.
eg if d1 was "green" then a1-a4 would be coloured green.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to color the cells based on the numeric value? ajyourpal Excel Worksheet Functions 1 June 24th 05 08:21 PM
Subtract a group of cells from a total based on ending date Nicholas Scarpinato Excel Discussion (Misc queries) 0 May 17th 05 03:25 PM
I want to format a cell based on an adjacent cells value Cumbo Excel Discussion (Misc queries) 1 December 13th 04 11:52 AM
how do you format a row of cells based upon a value in another ce. hazenb1 Excel Discussion (Misc queries) 1 December 9th 04 04:22 AM
conditional formating - Highlighting text cells based on sales res ANDREW_B Excel Discussion (Misc queries) 7 December 2nd 04 04:27 PM


All times are GMT +1. The time now is 06:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"