Trying to lock entire row from editing if value in column N = TRUE

asthmatic_weasel

New Member
Joined
Nov 18, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Good afternoon all,

I have a excel sheet that is an output from a powershell script. We will to run the powershell script again and want to make sure that certain rows are not overwritten. I am ok at VBA but not amazing by any standard and have tried to place the following code.

Private Sub Worksheet_Calculate()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Me.Unprotect
For i = 1 To LR
With Range("N" & i)
If .Value = "TRUE" Then .EntireRow.Locked = True
End With
Next i
Me.Protect
End Sub

However it still allows me to edit cells that should be locked. Does anyone think this would work? Am I close to getting it to work or am I completely wrong? Have I missed a step somewhere maybe?

Just for honesty and integrity that code above was found on the internet and I copied and adjusted as I saw suitable.

Any help or pointers would be great
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Perhaps, if the problem is the last rows, the data in column A is equal to the data in column N, I mean, is column N is longer than column A ?
 
Upvote 0
Update - It was a mistake on my part. I hadn't removed protection before apply the code. Once I had removed the workbook protection and then applied the code. it worked as I had hoped. I should always double check my work.
 
Upvote 0
Solution
Are you sure ? your macro already has .Unprotect/.Protect for Sheet protection and the Workbook protection doesn't affect your sheet. Maybe the issue was in the powershell script, not in the macro you showed.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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