View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1578_] Rick Rothstein \(MVP - VB\)[_1578_] is offline
external usenet poster
 
Posts: 1
Default How do I disable cell editing in vba?

You might consider something like the following. Copy/Paste the code below
into the code window for the worksheet you want to block entries on. Change
the two occurrences of the number 6 (used for Column F in my example) to the
number corresponding to the column you want to block entries on. What the
code will do is let the user change the value in the column, but then it
will advise the user he can't change the existing value and then replace
that entered value with the value that was in the cell originally.

Dim OldValue As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 Then
On Error GoTo Whoops
Application.EnableEvents = False
MsgBox "Values in this column cannot be changed!"
Target.Value = OldValue
End If
Whoops:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 6 Then OldValue = Target.Value
End Sub

Rick


"DRICE" wrote in message
...
I am trying to programmaticly (vba) prevent users from editing any cell in
one specific column without haveing to 'protect' the entire worksheet.