Clear Cell Fill when leaving Worksheet

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
 
D

Dave Peterson

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.
 
M

mpb

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
 

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