Protect columns and cells via VBA

anvs

New Member
Joined
Apr 18, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
In a spreadsheet, Col A is used to register processes.
In Col B and Col C are the results of the code in use.
From D2:G30 are the results of other calculations by formulas.
If it was possible:
I would like to protect the results of Col B and Col C and cells D2:G30, being able to continue to insert new processes in Col A and obtain the respective results in Col B and Col C.
I tried via ProtectedSheet but it does not record the results of the calculations.

Code in use:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim w
If Target.Column > 1 Then Exit Sub
Application.EnableEvents = False
w = Target: Application.Undo
If w <> Target Then
Target = w
If Target(, 2) = "" Then
Target(, 2) = Now
else
Target(, 3) = Now
End If
SendKeys "{DOWN}"
End If
Application.EnableEvents = True
End Sub

Thanks in advance.
anvs
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You could try just putting this in the worksheet selection change, which will make it very difficult to modify columns B and C
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not (Intersect(Target, Range("B:B")) Is Nothing) Then
 Cells(Target.Row, 1).Select
End If
If Not (Intersect(Target, Range("C:C")) Is Nothing) Then
 Cells(Target.Row, 4).Select
End If

End Sub
 
Upvote 0
The contents of all cells (Col B, Col C and other cells) can still be deleted.
 
Upvote 0
Have you tried it? , you can't select them so it is rather difficult to delete the contents
 
Upvote 0
Ok.
I made a small (clean) prototype to test code of the Roliis13 and work fine.
It will be a conflict within my sheet that I will try to resolve.
Thank you very much for your interest.
I appreciate the availability.
anvs
 
Upvote 0

Forum statistics

Threads
1,215,794
Messages
6,126,945
Members
449,349
Latest member
Omer Lutfu Neziroglu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top