Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a spreadsheet on which I want to change the background color of the
cell when the user clicks on it. Ex. If (selection).interior.colorindex = 0 then (selection).interior.colorindex = 4 else (selection.interior.colorindex = 0 end if. Basically I want to toggle the color between green and white for a give range of cells. How do I do it? Thank you all in advance. JB |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
JB
This should give you the basic idea: Public OldCell As Range Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Intersect(Target, Range("A1:C8")) Is Nothing Then Exit Sub If Target.Cells.Count 1 Then Exit Sub If OldCell Is Nothing Then Set OldCell = Target OldCell.Interior.ColorIndex = 0 Target.Interior.ColorIndex = 4 End Sub The routine needs to be in the Sheet Class Module for the sheet where you want to operate. Right click on the sheet tab, View Code, and paste the code above. This limits the range to A1 to C7 ... just amend to suit your requirements Regards Trevor "JEB" wrote in message ... I have a spreadsheet on which I want to change the background color of the cell when the user clicks on it. Ex. If (selection).interior.colorindex = 0 then (selection).interior.colorindex = 4 else (selection.interior.colorindex = 0 end if. Basically I want to toggle the color between green and white for a give range of cells. How do I do it? Thank you all in advance. JB |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you. It worked as expected.
"Trevor Shuttleworth" wrote: JB This should give you the basic idea: Public OldCell As Range Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Intersect(Target, Range("A1:C8")) Is Nothing Then Exit Sub If Target.Cells.Count 1 Then Exit Sub If OldCell Is Nothing Then Set OldCell = Target OldCell.Interior.ColorIndex = 0 Target.Interior.ColorIndex = 4 End Sub The routine needs to be in the Sheet Class Module for the sheet where you want to operate. Right click on the sheet tab, View Code, and paste the code above. This limits the range to A1 to C7 ... just amend to suit your requirements Regards Trevor "JEB" wrote in message ... I have a spreadsheet on which I want to change the background color of the cell when the user clicks on it. Ex. If (selection).interior.colorindex = 0 then (selection).interior.colorindex = 4 else (selection.interior.colorindex = 0 end if. Basically I want to toggle the color between green and white for a give range of cells. How do I do it? Thank you all in advance. JB |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Changing cell text color based on cell number | Excel Programming | |||
Changing cell text color based on cell number | Excel Programming | |||
Cell colors or text color changing when date in cell gets closer. | Excel Worksheet Functions | |||
Code for making a cell chage color by dbl clicking, with either a | Excel Programming | |||
changing cell value by double clicking it with out vba/macros | Excel Programming |