Highlight active cell and de-highlight previous cell

D

dmbuso

I want to highlight the current cell with a color say gray and set the color
of the last cell I was at back to what it currently was. The code below does
not work. It sets the previous cell color to white and if the cell color was
something other than white, say green, I lose the color green for the
previous cell.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next

Static OldRange As Range

'Set backcolor to whatever, change as needed
Target.Interior.ColorIndex = 15 'light gray

OldRange.Interior.ColorIndex = xlColorIndexNone
Set OldRange = Target

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top