Forum Discussion
TonyCrabb
Apr 29, 2022Copper Contributor
How can i protect a calculated column in a table from being edited but allowing users to add rows?
Hi, I have a simple example of a data entry form (on an excel table) with 4 columns for entry of quarterly financial data. i have a 5th column that adds up the 4 quarters into an annual cost per line...
HansVogelaar
May 04, 2022MVP
That is too difficult (we don't know how the user arrived there), but you can do something like this if you really want to irritate your users:
- Right-click the sheet tab.
- Select View Code from the context menu.
- Copy the code listed below into the worksheet module.
- Change Range("F:F") to the column you want to make inaccessible.
- If you ever want to edit the column, type the following in the Immediate window of the Visual Basic Editor and press Enter:
Application.EnableEvents = False - When you're done, do the same but with
Application.EnableEvents = True - Don't forget this, otherwise the worksheet won't react to events anymore.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("F:F"), Target) Is Nothing Then
Application.EnableEvents = False
Beep
Range("A1").Select
Application.EnableEvents = True
End If
End Sub
TonyCrabb
May 04, 2022Copper Contributor
Thanks HansVogelaar. instead of the beep and going to A1, can you find current row and just move the cursor automatically to Col E on current row?
- TonyCrabbMay 04, 2022Copper ContributorThanks HansVogelaar - you have been very helpful. I need to sleep on this one and have a think about where to go next.
- HansVogelaarMay 04, 2022MVP
You can remove the Beep line and change Range("A1").Select to Range("E" & Target.Row).Select