PDA

View Full Version : saved colour



aoc
06-09-2011, 11:39 PM
Dear All,

What should I do if I want below code run automatically whenever I open a new workbook ? And there is a problem. When I select a cell it is coloured If I save the file and close and reopen the cell is still coloured how can I prevent this ?

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)

Static OldRange As Range
On Error Resume Next
Target.Interior.ColorIndex = 3
OldRange.Interior.ColorIndex = xlColorIndexNone

Set OldRange = Target
End Sub

Bob Phillips
06-10-2011, 12:12 AM
Put it in the Workbook_Open event.

aoc
06-10-2011, 02:54 AM
Hi Xld,

I tried but I receive error when I open the workbook. I attached the file

Bob Phillips
06-10-2011, 03:17 AM
You don't embed one event procedure within another.

Instead of



Sub WorkBook_Open()

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)

Static OldRange As Range
On Error Resume Next
Target.Interior.ColorIndex = 3
OldRange.Interior.ColorIndex = xlColorIndexNone

Set OldRange = Target
End Sub

End Sub

It should be



Private Sub WorkBook_Open()

Static OldRange As Range
On Error Resume Next
Target.Interior.ColorIndex = 3
OldRange.Interior.ColorIndex = xlColorIndexNone

Set OldRange = Target
End Sub

aoc
06-12-2011, 10:20 PM
Hi,

it does not work

Aussiebear
06-13-2011, 03:19 AM
What error message do you receive?