View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Simon Letten Simon Letten is offline
external usenet poster
 
Posts: 20
Default Hilight The Currently Active Cell

Aha! Now that's a little bit more involved. You need to store the colours of
all the cells previously selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngPrevValue As Range
Dim cell As Range

Set rngPrevValue = ThisWorkbook.Worksheets("Sheet2").Range("A1") ' <--
change this if need be
'set previous selection back to orig colour
Do Until IsEmpty(rngPrevValue)
Range(rngPrevValue.Value).Interior.ColorIndex =
rngPrevValue.Offset(ColumnOffset:=1).Value
'clear the values
rngPrevValue.Resize(ColumnSize:=2).ClearContents
' movedown to next value stored
Set rngPrevValue = rngPrevValue.Offset(RowOffset:=1)
Loop
Set rngPrevValue = ThisWorkbook.Worksheets("Sheet2").Range("A1") '<--
same as before

' store current values before changing them
For Each cell In Target
rngPrevValue.Value = cell.Address(External:=True)
rngPrevValue.Offset(ColumnOffset:=1).Value = cell.Interior.ColorIndex
Set rngPrevValue = rngPrevValue.Offset(RowOffset:=1)
Next cell
Target.Interior.ColorIndex = 3

If Not (rngPrevValue Is Nothing) Then Set rngPrevValue = Nothing

End Sub

--


Simon


"xcelion" wrote:


Thank simon.
But what about resetting color back to orginal color once the selection
is lost ?


--
xcelion
------------------------------------------------------------------------
xcelion's Profile: http://www.excelforum.com/member.php...o&userid=16287
View this thread: http://www.excelforum.com/showthread...hreadid=396407