ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   In a Shared Workbook of Excel, how do I change the color of a Cel. (https://www.excelbanter.com/excel-programming/327011-shared-workbook-excel-how-do-i-change-color-cel.html)

ahmed

In a Shared Workbook of Excel, how do I change the color of a Cel.
 
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.

Pete[_22_]

In a Shared Workbook of Excel, how do I change the color of a Cel.
 
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.




ahmed

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.






All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com