#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ColorIndex

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default ColorIndex

Hi Trevor

In Excel 2002/2003 you can protect you sheet with
"Allow Format Cells" checked

You code is working then


If you use 97/2000
You must protect your sheet with code like this

Protect your worksheets with code with userfaceonly like this
Place this in the Thisworkbook module.

The macro's will be working now
It will only protect the userfaceonly

Right click on the Excel icon next to File in the menubar
And choose View code

You are now in the Thisworkbook module
Paste the Event in this place
Alt-Q to go back to Excel

Private Sub Workbook_Open()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
sh.Protect "ABCD", , , userinterfaceonly:=True
Next sh
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Trevor Davidson" wrote in message ...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default ColorIndex

Hi Trevor
which Excel version are you using?.
In later versions you can enable formating cells

--
Regards
Frank Kabel
Frankfurt, Germany


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default ColorIndex

Wrap it in Unprotect, Protec

Sub Worksheet_SelectionChange(ByVal target As Range) If Range("C23") < 8 The
ActiveWorkbook.UnProtect Password := "Your password here ' if no pass word, just use ActiveWorkbook.UnProtec

Range("C8:C22").Interior.ColorIndex =
Els
Range("C8:C22").Interior.ColorIndex = 4
End I
ActiveWorkbook.Protect Password := "Your password here

End Su


----- 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 Hel

Sub Worksheet_SelectionChange(ByVal target As Range
If Range("C23") < 8 The
Range("C8:C22").Interior.ColorIndex =
Els
Range("C8:C22").Interior.ColorIndex = 4
End I
End Su

  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default ColorIndex

Microsoft 2000
-----Original Message-----
Hi Trevor
which Excel version are you using?.
In later versions you can enable formating cells

--
Regards
Frank Kabel
Frankfurt, Germany


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

.



  #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

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ColorIndex skat Excel Worksheet Functions 5 June 5th 06 02:42 AM
colorindex Nell Fahey Excel Discussion (Misc queries) 3 April 28th 05 07:06 PM
ColorIndex K Bro Excel Programming 2 February 7th 04 04:42 PM
ColorIndex K Bro Excel Programming 0 February 7th 04 03:30 PM


All times are GMT +1. The time now is 11:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"