View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ahmed ahmed is offline
external usenet poster
 
Posts: 22
Default In a Shared Workbook of Excel, how do I change the color of a

Thank you, Pete, for responding. However, I get the following error message
when I attempt to run your code: "Unable to set the ColorIndex property of
the Interior Class.

I've been using the following code, but it does not work with a Shared
Workbook:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iColor As Integer

'// Note: Don't use if you have conditional
'// formatting that you want to keep

'// On error resume in case user selects a range of cells
On Error Resume Next
iColor = Target.Interior.ColorIndex

'// Leave On Error ON for Row offset errors
If iColor < 0 Then
iColor = 36
Else
iColor = iColor + 1
End If

'// Need this test in case Font color is the same
If iColor = Target.Font.ColorIndex Then iColor = iColor + 1
Cells.FormatConditions.Delete

'// Horizontal color banding
With Range("Z" & Target.Row, Target.Address) 'Rows(Target.Row)
.FormatConditions.Add Type:=2, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = iColor
End With


End Sub

"Pete" wrote:

Ahmed

Try putting this code on the sheet.
(Get into VBA and then Double-click on the sheet object)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
ActiveCell.Interior.ColorIndex = 6
End Sub

Peter Bircher

"Ahmed" wrote in message
...
In a Shared Workbook of Excel, how do I change the color of a Cell by
simply
selecting it. For example, if I click on Cell B234 making it the Active
Cell, I want the color of Cell G234 to change to yellow.