If you're using xl2002+ (I think this feature was added in xl2002???).
You can protect the sheet, but allow some users to edit certain ranges.
In xl2003 menus:
tools|protection|allow users to edit ranges
Remember that this works only after the sheet is protected.
But if you wanted to use code, I don't think I'd use the workbook_sheetchange
event.
Either the sheet's Worksheet_SelectionChange event or the Worksheet_Change event
would make more sense to me. (But either of these would only work if macros are
enabled and events are enabled.)
Only use one of these--not both.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRngToInspect As Range
Dim myPWD As String
Dim UserPWD As String
myPWD = "myPassWorD"
Set myRngToInspect = Me.Range("C300")
If Intersect(Target, myRngToInspect) Is Nothing Then
Exit Sub
End If
UserPWD = InputBox(Prompt:="What's the password, Kenny?")
If UserPWD <> myPWD Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
MsgBox "Incorrect password for this cell--reverting to old value!"
End If
End Sub
Or use the _selectionchange event...
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myRngToInspect As Range
Dim myPWD As String
Dim UserPWD As String
myPWD = "myPassWorD"
Set myRngToInspect = Me.Range("C300")
If Intersect(Target, myRngToInspect) Is Nothing Then
Exit Sub
End If
UserPWD = InputBox(Prompt:="What's the password, Kenny?")
If UserPWD <> myPWD Then
With Application
.EnableEvents = False
.Goto Me.Range("A1") 'send them somewhere else
.EnableEvents = True
End With
MsgBox "Incorrect password for this cell--You can't select it!"
End If
End Sub
These routines don't go into the the ThisWorkbook module. They (just one) go
under the sheet that should have this behavior.