View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Change Interior Cell Color

Ken

This code from Don Guillett will do the trick.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 20
End With
End Sub


Gord Dibben MS Excel MVP

On Mon, 6 Aug 2007 15:10:02 -0700, Ken Hudson
wrote:

I have a worksheet whose cells have different interior colors. When I select
a cell, I want to change the interior color to 35. When I move on to another
cell, I want to change that color back to its original color.
I found the following code to make the intial change, but haven't figured
out how to return the original color.
Thanks for helping.

---------------------------------

Option Explicit
Dim OldActiveCell As Range

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
If OldActiveCell Is Nothing Then
Set OldActiveCell = Target
Else
OldActiveCell.Interior.ColorIndex = xlNone
End If
Target.Interior.ColorIndex = 35
Set OldActiveCell = Target
End Sub