View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Script Not working

Thanks Rick

Appreciate the updates.


Gord

On Sat, 6 Sep 2008 13:45:54 -0400, "Rick Rothstein"
wrote:

You can prevent the background color and borders destruction by storing the
relevant properties in their own Static variables and resetting them before
updating the OldCell properties. Here is your code modified to do that...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static OldCell As Range
Static OldInterior As Long
Static OldBorders As Long
If Application.CutCopyMode = 0 Then
ActiveSheet.Unprotect Password:="justme"
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = OldInterior
OldCell.Borders.LineStyle = OldBorders
End If
Set OldCell = Target
OldInterior = Target.Interior.ColorIndex
OldBorders = Target.Borders.LineStyle
OldCell.Interior.ColorIndex = 6
OldCell.Borders.LineStyle = xlContinuous
Else
If OldCell Is Nothing Then
Set OldCell = Target
Else
Set OldCell = Union(OldCell, Target)
End If
End If
ActiveSheet.Protect Password:="justme"
End Sub

Also, you might want to add this line...

If Target.Count < 1 Then Exit Sub

at the beginning of the code to prevent the error that occurs when multiple
cells are selected (unless you think it necessary to expand the code to
handle coloring and re-coloring multiple cells, which would complicate
things a little).