View Single Post
  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default Write once cells

Here is one way.

Add this code to the worksheet in question (change the range in
RANGE_MONITOR to your range)

Private Sub Worksheet_Change(ByVal Target As Range)
Const RANGE_MONITOR As String = "H1:H10"
Dim sPW As String
On Error GoTo ws_exit:
sPW = Evaluate(ThisWorkbook.Names("___pw").RefersTo)
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(RANGE_MONITOR)) Is Nothing Then
With Target
Me.Unprotect Password:=sPW
.Locked = True
Me.Protect Password:=sPW
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

Then run this code on the worksheet, but delete it afterwards, don';t leave
it around

Sub SetupSheet()
ActiveSheet.Cells.Locked = False
ActiveWorkbook.Names.Add Name:="___pw", RefersTo:="ABCD"
ActiveWorkbook.Names("___pw").Visible = False
ActiveSheet.Protect Password:="ABCD"
End Sub

Change the password to suit.


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"HuckinD" wrote in message
...

Is there any way that I can write a macro or code for a quiz sheet I
have made.
I want my pupils to be able to type into the cell but would like it
lock the cell after they have typed something in so effectively I can
use it as a test but the first answer is the one that counts.
Somebody suggested that I rightclick on the workbook tab and then use
the view code function, but I know nothing about computer code and
would not know what to write in the boxes
Any ideas would be greatly appreciated.
Thanks
Dave


--
HuckinD