• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Is there any code which will deactivate the access to delete certain rows

ThrottleWorks

Excel Ninja
Sir,


I have an important file, this file contains macros, the macro I have prepared is not generic.


Sir is there any code which will deactivate the access to delete certain rows from the workbook.


For example my file has 3 different tabs, 1st 4 rows are extremely important from macro point.

If someone delete any of these rows , the macro will develop bug.


I want to deactivate access to delete these rows, is it possible by VBA.


Can anyone help me in this please.
 
Hi Sachinbizboy,


You can protect the sheet (with password) by locking the rows that you deem vital.


How:

1. select all the cells, > format > protection > uncheck the "locked" check box.

2. select your vital rows, > format > protection > Check the "locked" check box.


3. Under review ribbon> changes group > Protect ksheet > enter password.

4. Re-enter password re-confirmation > Ok.


Its now only those who know password can unprotect the sheet and delete those rows else, they cannot edit, or delete those rows.


Regards,

Prasad DN

PS: This may affect your vba code, test it once you have protected. If any issue comes up then thru vba add line sheet.unprotect "<password>" to unprotect and again protect them back with sheet.protect "<password>"

PSS: Sachin made century of centuries, finally!!
 
Prasad Sir, thanks a lot for the support & your valuable time, sorry for delay in reply.


AND yes Sachin made 100 * 100, Statisticians will be working overtime today, congrats to us.
 
Another idea would be to try and "catch" the change, and undo it. Here's an example using the Worksheet_Change event:

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("1:4")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Application.Undo
MsgBox "Don't touch rows 1 through 4!", vbCritical + vbOKOnly, "DON'T DO THAT!"
Application.EnableEvents = True
End Sub
[/pre]
This macro would need to be installed on the Sheet module for each sheet that you want affected.
 
Luke Sir, you are awesome, this is really great, thanks lot.


Have a nice weekend Sir,


Prasad Sir, Luke Sir thanks a lot to both of you for your great support & valuable time.
 
Back
Top