Thread: ColorIndex
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default ColorIndex

Can you use ActiveWorkbook.unprotect under Sub Worksheet?
-----Original Message-----
Wrap it in Unprotect, Protect

Sub Worksheet_SelectionChange(ByVal target As Range)

If Range("C23") < 8 Then
ActiveWorkbook.UnProtect Password := "Your password

here ' if no pass word, just use ActiveWorkbook.UnProtect

Range("C8:C22").Interior.ColorIndex = 6
Else
Range("C8:C22").Interior.ColorIndex = 44
End If
ActiveWorkbook.Protect Password := "Your password here"

End Sub



----- Trevor Davidson wrote: -----

The Code below works just fine when the Worksheet is
unprotected.
The problem starts when I protect the worksheet.

All
cells in the code are unprotected.
I get an error 1004.

Please Help

Sub Worksheet_SelectionChange(ByVal target As Range)
If Range("C23") < 8 Then
Range("C8:C22").Interior.ColorIndex = 6
Else
Range("C8:C22").Interior.ColorIndex = 44
End If
End Sub

.