This sub needs to be placed as a WorkSHEET module for Sheet5
I have comment out the protection steps - you can manually protect the work
sheet as needed, or just remove the single quote that makes the VBA line a
comment. Likewise add a single quote in front of Msgbox lines to make them
comments (I use this to test my code)
You may get an error the first time the code tries to lock the cells if they
are already locked.
It will work on other computers because the code is part of the workbook.
People sometime have put code in a special file (PERSONAL.XLS) and that code
will be seen only on the computer that is home to PERSONAL.XLS.
You need to be aware what some people have Excel set in a way that prevents
macros from running. You should warn the people who will get the file that
you have a macro - hopefully they are under you in the organizational chart
so you can 'boss' them!
To learn more about VBA see David McRitchie's site on "getting started" with
VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm
Here is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("G21")) Is Nothing Then
If Range("G21").Value <> 2002 Then
Worksheets("Sheet3").Range("B1:H10").Locked = True
' Worksheets("Sheet3").Protect
MsgBox "locked"
Else
Worksheets("Sheet3").Range("B1:H10").Locked = False
' Worksheets("Sheet3").UnProtect
MsgBox "unlocked"
End If
End If
End Sub
best wishes