Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following code in the Worksheet_Change event of a worksheet.
Case "$E$14" 'Approval status If Target.Value < "" Then If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If End If The code works fine, until I turn on the Protect Sheet feature. Then it generates an error code 1004 (Application-defined or object-defined error). Does anyone know why protecting the worksheet would cause the code to fail? Ken |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ken,
This is probably because the 'AllowFormattingCells' property is set to false. If you are manually protecting the sheet you can put a tick next to 'Format Cells' in the Protect Sheet dialog. HTH, Nick H |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Nick,
That's the answer I was looking for. Thanks for the help. Ken "Nick H" wrote: Hi Ken, This is probably because the 'AllowFormattingCells' property is set to false. If you are manually protecting the sheet you can put a tick next to 'Format Cells' in the Protect Sheet dialog. HTH, Nick H |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Assuming you allow any cell by any user to change the format?
-- Regards, Nigel "Ken Warthen" wrote in message ... Nick, That's the answer I was looking for. Thanks for the help. Ken "Nick H" wrote: Hi Ken, This is probably because the 'AllowFormattingCells' property is set to false. If you are manually protecting the sheet you can put a tick next to 'Format Cells' in the Protect Sheet dialog. HTH, Nick H |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ken,
Unprotect at runtime and the re-protect Case "$E$14" 'Approval status If Target.Value < "" Then ActiveSheet.Unprotect Password:="MyPass" If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If ActiveSheet.Protect Password:="MyPass" End If Mike "Ken Warthen" wrote: I have the following code in the Worksheet_Change event of a worksheet. Case "$E$14" 'Approval status If Target.Value < "" Then If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If End If The code works fine, until I turn on the Protect Sheet feature. Then it generates an error code 1004 (Application-defined or object-defined error). Does anyone know why protecting the worksheet would cause the code to fail? Ken |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mike,
That doesn't seem very practical since anytime any cell value changes the code runs. Ken "Mike H" wrote: Ken, Unprotect at runtime and the re-protect Case "$E$14" 'Approval status If Target.Value < "" Then ActiveSheet.Unprotect Password:="MyPass" If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If ActiveSheet.Protect Password:="MyPass" End If Mike "Ken Warthen" wrote: I have the following code in the Worksheet_Change event of a worksheet. Case "$E$14" 'Approval status If Target.Value < "" Then If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If End If The code works fine, until I turn on the Protect Sheet feature. Then it generates an error code 1004 (Application-defined or object-defined error). Does anyone know why protecting the worksheet would cause the code to fail? Ken |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
But that portion of the code would only run if you've changed E14 and E14 is not
"". And the worksheet would be unprotected for a very short period of time. And since this in in the worksheet_change event (I'd guess), I'd do: Case "$E$14" 'Approval status If Target.Value < "" Then me.unprotect Password:="MyPass" If lcase(Target.Value) = lcase("Not Submitted") Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If me.protect password:="MyPass" End If The Me keyword refers to the object owning the code. In this case, I'm guessing it's the worksheet getting the change. And I'd watch out for upper/lower case differences in the string comparison. Ken Warthen wrote: Mike, That doesn't seem very practical since anytime any cell value changes the code runs. Ken "Mike H" wrote: Ken, Unprotect at runtime and the re-protect Case "$E$14" 'Approval status If Target.Value < "" Then ActiveSheet.Unprotect Password:="MyPass" If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If ActiveSheet.Protect Password:="MyPass" End If Mike "Ken Warthen" wrote: I have the following code in the Worksheet_Change event of a worksheet. Case "$E$14" 'Approval status If Target.Value < "" Then If Target.Value = "Not Submitted" Then Target.Font.Color = 255 Else Target.Font.Color = 0 End If End If The code works fine, until I turn on the Protect Sheet feature. Then it generates an error code 1004 (Application-defined or object-defined error). Does anyone know why protecting the worksheet would cause the code to fail? Ken -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Changing macro security causes VBA code to fail | Excel Programming | |||
Range("Reset Sheet!F13").Select Makes VBA Code Fail | Excel Programming | |||
Placement of variables in called sub causes code to fail | Excel Programming | |||
Links to 2nd closed worksheet fail when using offset function ?? | Excel Worksheet Functions | |||
Protecting buttons with VB code rather than protecting sheets/books? | Excel Programming |