Clear fill colour of last cell on save

trebor1956

Board Regular
Joined
Jul 2, 2015
Messages
100
Office Version
  1. 2013
Platform
  1. Windows
Hi,
I use the following code to highlight he active cell and it works fine, but when I save the workbook the last cell selected stays wit the highlighted colour. On save I would like to select say cell A1 and clear the fill colour.

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
'Update 20140923
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 8
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub

Hope you can help.....
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Thanks,

But what code s required t go to A1 and then clear fill from A1 please?


Hi,
I use the following code to highlight he active cell and it works fine, but when I save the workbook the last cell selected stays wit the highlighted colour. On save I would like to select say cell A1 and clear the fill colour.

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
'Update 20140923
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 8
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub

Hope you can help.....
 
Upvote 0
Thanks, but what code do I need to go to cell A1 and clear the fill from A1 please?
 
Upvote 0
Thanks, but what code do I need to go to cell A1 and clear the fill from A1 please?
This is where the Macro Recorder is your best friend! It is a great tool to use in helping to create your own VBA code.
Turn on the Macro Recorder, and record yourself performing those steps manually, and you will have the VBA code that you need.
Try it out for yourself!
Post back here if you run into issues.
 
Upvote 0
This is where the Macro Recorder is your best friend! It is a great tool to use in helping to create your own VBA code.
Turn on the Macro Recorder, and record yourself performing those steps manually, and you will have the VBA code that you need.
Try it out for yourself!
Post back here if you run into issues.

Thanks, that worked fine.
 
Upvote 0
Thanks, that worked fine.
Excellent! Glad to hear it!
:)

The Macro Recorder is a handy tool that even us "pros" use (you don't think we remember all this stuff, do you;))?
 
Upvote 0
When I open my workbook with the mentioned macro a cell is yellow when I go to another cel the first cel is stil yellow. What can I do to prvent that?
 
Upvote 0
When I open my workbook with the mentioned macro a cell is yellow when I go to another cel the first cel is stil yellow. What can I do to prvent that?
Please post the code that you are using, and explain exactly what you want to happen.
 
Upvote 0
Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
'Update 20140923
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 6
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub

this is the code, When I open my workbook a random cel where the cusor is at that moment is yellow. When I move to another cel that cel becomes yellow but the first one is still yellow and that should not happen that cell should be return to its default state.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top