Clear Cell Fill when leaving Worksheet

  • Thread starter Thread starter mpb
  • Start date Start date
M

mpb

Good Morning All,

I am looking for some code to clear a cell fill when leaving the
worksheet.
ie I have a command button which goes to a specific cell on another
worksheet (based on the value in another worksheet) & fills yellow.
Now when I leave the worksheet (and go to another), I would like the
fill to be removed.

Any help, as usual most appreciated.
Cheers
Mathew
 
There is a worksheet_deactivate event you could tie into:

Option Explicit
Private Sub Worksheet_Deactivate()
Me.Range("A1").Interior.ColorIndex = xlNone
End Sub

Another option would be to use the worksheet_activate event. That way the cell
will have its fill color cleared when you come back to it.

This kind of event code goes in the worksheet module for that sheet.
 
There is a worksheet_deactivate event you could tie into:

Option Explicit
Private Sub Worksheet_Deactivate()
     Me.Range("A1").Interior.ColorIndex = xlNone
End Sub

Another option would be to use the worksheet_activate event.  That way the cell
will have its fill color cleared when you come back to it.

This kind of event code goes in the worksheet module for that sheet.

Thank you very much Dave, always a mine of information.
Did not even realize that there was a Worksheet Activate/Deactivate
Cheers Again
Mathew
 
Back
Top