VBA - allow user to delete a "locked" cell

Geordie

Board Regular
Joined
Oct 16, 2006
Messages
143
Morning All,

I have some formulas which are protected, so Ive put a password on the sheet. Problem is that I want the user to be able to delete rows... when I try and delete a row with the protection on I get the following error.

You are trying to delete a row that contains a locked cell. Locked cells cannot be deleted while the worksheet is protected.

Is there any code I can use to get around this? My protected columns are A and some of D.

Thanks,
Mandy
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hello Mandy

Do you want to do this with VBA? You can get your users to call this macro when they want to delete row(s). Change the password to reflect thje one you are currently using. The macro deletes ALL rows based on the selected region.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DelRow()<br><br>ActiveSheet.Unprotect "PASSWORD"<br>    Selection.EntireRow.Delete<br>ActiveSheet.Protect "PASSWORD"<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Thanks,

I just accidently deleted some rows.... (Doh)... so figuring if I can easily do it then users can.


How do I add a msg box around this to ask them if they are sure?

M
 
Upvote 0
Sure:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DelRow()<br><br><SPAN style="color:#00007F">Dim</SPAN> msg<br><br>msg = MsgBox("Are you sure?", vbYesNo)<br>    <SPAN style="color:#00007F">If</SPAN> msg = vbNo <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br>ActiveSheet.Unprotect "PASSWORD"<br>    Selection.EntireRow.Delete<br>ActiveSheet.Protect "PASSWORD"<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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