View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Change background colour of selected cells

Paste this to the worksheet's code module:-

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

The downside of using worksheet event code is that it kills the contents of
the clipboard. You will notice that if you copy something and then attempt to
paste it to another cell the Paste button is grayed. You will need code to
correct this.

Alternatively, you can still drag and drop to cut and paste. And if you hold
down the Ctrl key and drag and drop it will copy and paste.

Regards,
Greg


"Redleg" wrote:

I wish to change the background colour of any selected cell on entry and
revert to original colour (none) on exit.