View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Ardus Petus
 
Posts: n/a
Default Change Cell Color when another cell is selected

Paste following code into Worksheets's code
(right-click on sheet tab, select View Code)

HTH
--
AP

'--------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const sWatchRange = "B2:E30" ' <== Change
Static rOldCell As Range
Dim rRowHeader As Range
Dim rColHeader As Range

If Not rOldCell Is Nothing Then
setHeaderColor rOldCell, xlColorIndexNone
End If
If Intersect(ActiveCell, Range(sWatchRange)) Is Nothing Then Exit Sub
setHeaderColor ActiveCell, 6
Set rOldCell = ActiveCell
End Sub

Sub setHeaderColor(rCell As Range, iColor As Integer)
Dim rRowHeader As Range
Dim rColHeader As Range

Set rRowHeader = Cells(rCell.Row, 1)
Set rColHeader = Cells(1, rCell.Column)
With Union(rRowHeader, rColHeader)
.Interior.ColorIndex = iColor
End With
End Sub
'----------------------------------------
"Toto Sanderson" a écrit dans le
message de news: ...
Hi all,

I've been searching this group, couldn't find answers to my question
below:

Row 1 is name of the places
Column A is dates of the year.

When a cell is selected in the area in the middle, I would like the place
name and date in Row1 and ColumnA to be highlighted as well.

I know there is a RowLiner that you can download and use, but it's not
really working. I guess it's because Row1 and ColumnA are splited and
frozen
pane.

Anything that we could do in conditional formatting or even VBA?

Thanks in advance

Toto Sanderson