I've used this:
Option Explicit
Public bInTable As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
' prevent changes to formula cells
If Cells(1, Target.Column) <> "" Then
If Not bInTable Then
Exit Sub
Else
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
MsgBox "Please do not make changes in this column", , _
"Changes not permitted"
Exit Sub
End With
End If
End If
End Sub
With this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lLR As Long
' establish range
With Me
' last row of data based on column A
lLR = .Range("A" & .Rows.Count).End(xlUp).Row
End With
If Target.Row <= lLR Then
bInTable = True
Else
bInTable = False
End If
End Sub
Basically, the Selection Change code determines if the cell selected is in the body of the table and sets a boolean flag. Then, if they make changes in the table area, the Worksheet Change event checks if row 1 is empty. If it's not, that column contains a formula ... the code undoes the change and displays a message.
If they make changes outside the table area, I don't care.
I have also considered checking the colour of the cell. In another project, I have used a Red interior colour to indicate that the column should not be changed and a Green interior colour to say that it can (take manual input) ... although I haven't put the protection code in place on this one.
Regards, TMS
Bookmarks