conditional formatting on click

  • Thread starter Thread starter beverlydawn
  • Start date Start date
B

beverlydawn

I want a cell to turn grey when clicked on, also to be clear if clicked on
after it has been grey. Is that possible?
 
Right click on the tab and pull down to View Source

Paste this in the source for the sheet that is being modified

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

With Target.Interior
If .ColorIndex <> 15 Then
.ColorIndex = 15
Else
.ColorIndex = -4142
End If
End With

End Sub
 
Try this worksheet event macro. It is coded for cell B9, but you can adjust
to suit your needs:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set t = Target
Set r = Range("B9")
If Intersect(t, r) Is Nothing Then Exit Sub
If r.Interior.ColorIndex = 15 Then
r.Interior.ColorIndex = xlNone
Else
r.Interior.ColorIndex = 15
End If
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

Back
Top