Conditional Format for cell protection?

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

Hello, Can anyone tell me if theres a way in Ex2000 to use conditional
formatting to set whether a cell is protected or not?. IE if a certain
condition is met then set that cells format-protection to locked. I know
how to set its font/color etc under certain conditions but seems to me
you should be able to set protection as well

If not I think it would be a good addition in conditional format
options, dont u think Mr Gates?
 
Mr. Gates sent me to check up on Frank <vbg>. By the way, Bill (as I like to
call him) says "hi, Frank".

Say you want to lock cells in column A that get bigger than 100 as the result of
typing. (Formula cells on your worksheet should already be locked, right???)

Right click on the worksheet tab that should behave this way. Select View
Code. Paste this into the code window.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myPWD As String
myPWD = "hi"

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then Exit Sub
If Me.ProtectContents = False Then Exit Sub

On Error GoTo errHandler:

With Target
If IsNumeric(.Value) Then
If .Value > 100 Then
Me.Unprotect Password:=myPWD
.Locked = True
Me.Protect Password:=myPWD
End If
End If
End With

errHandler:
Me.Protect Password:=myPWD

End Sub


Don't forget to lock the VBA Project, too. Else you'll have inquisitive types
looking at your code and seeing the password.

Inside the VBE, you can lock the project.
Tools|VBAProject Properties|Protection tab.
Give it a memorable password and lock the project for viewing.

That said, worksheet protection is very weak. There's code posted here every
day/week that would unprotect the worksheet.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


=======
And since you're not going to use conditional formatting for this, you can
indicate whether the cell is locked:

Select your range and use a formula is:
=CELL("protect",A1)
where A1 is the activecell.

(give it a nice pattern and see what happens.)

It makes seeing the results of testing easier, too.
 
Dave said:
Mr. Gates sent me to check up on Frank <vbg>. By the way, Bill (as
I like to call him) says "hi, Frank".

Hi Dave
thanks for this.
Oh btw I have a "small" list of feature requirements for Bill. So can
you forward them for me <ebg>

Frank
 
Dave Peterson said:
Heck, I'll ask him to send the jet for you.

lol
next week would be suitable as we have a long weekend here in Germany
<vbg>

Best regards
Frank
 
Back
Top