Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Changing cell color based on cell value

I have 6 variables, they are 1, 2, 3, 4, 5 and 6.
I would like to have a cell have a dropdown menu where the user can select
which of the six variables they want. Depending on which variable is chosen,
that cell and the cell above it will change to a specific color that is
associated with each variable.

Thanks!!!
Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Changing cell color based on cell value

Select the cell
data=Validation= select the list option. In the textbox put

1,2,3,4,5,6

click OK

Right click on the sheet tab and select view code

Assume the cell with the dropdown is B9.

Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i as Long
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$9" Then
Set rng = Range("B8:B9")
Select Case Target.Value
Case 1
i = 3
Case 2
i = 7
Case 3
i = 2
Case 4
i = 12
Case 5
i = 9
Case 6
i = 4
Case Else
i = xlNone
End Select
rng.Interior.ColorIndex = i
End If
End Sub

--
Regards,
Tom Ogilvy



"Mr. Dan" wrote in message
...
I have 6 variables, they are 1, 2, 3, 4, 5 and 6.
I would like to have a cell have a dropdown menu where the user can select
which of the six variables they want. Depending on which variable is
chosen,
that cell and the cell above it will change to a specific color that is
associated with each variable.

Thanks!!!
Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Changing cell color based on cell value

Thanks Tom! Works perfectly!!!

"Tom Ogilvy" wrote:

Select the cell
data=Validation= select the list option. In the textbox put

1,2,3,4,5,6

click OK

Right click on the sheet tab and select view code

Assume the cell with the dropdown is B9.

Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i as Long
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$9" Then
Set rng = Range("B8:B9")
Select Case Target.Value
Case 1
i = 3
Case 2
i = 7
Case 3
i = 2
Case 4
i = 12
Case 5
i = 9
Case 6
i = 4
Case Else
i = xlNone
End Select
rng.Interior.ColorIndex = i
End If
End Sub

--
Regards,
Tom Ogilvy



"Mr. Dan" wrote in message
...
I have 6 variables, they are 1, 2, 3, 4, 5 and 6.
I would like to have a cell have a dropdown menu where the user can select
which of the six variables they want. Depending on which variable is
chosen,
that cell and the cell above it will change to a specific color that is
associated with each variable.

Thanks!!!
Dan




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
Changing the color of a cell based on the color of another cell. LATC Excel Discussion (Misc queries) 7 December 4th 09 09:49 PM
Changing Cell Background Color based on data from another cell Speedy Excel Discussion (Misc queries) 2 March 16th 09 04:10 PM
Changing a color in a cell based on the text in another cell Ryan Excel Discussion (Misc queries) 3 November 13th 08 10:17 PM
changing value of a cell based on another cell color Gary Excel Discussion (Misc queries) 2 January 30th 05 10:19 AM
Changing cell color based on its value spolk[_8_] Excel Programming 9 June 1st 04 08:24 AM


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

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

About Us

"It's about Microsoft Excel"