Excel Problem - Delete Row Macro

T

thesteelmaker

I have a protected worksheet, to stop people deleting thing
unnecessarily. Although some rows need to be deleted occasionally.

I want to delete these rows using a macro that unprotects the sheet
deletes the row that has been selected and then protects the shee
again.

I created the following macro, which works:

Sub DeleteMealItem()
ActiveSheet.Unprotect
Selection.EntireRow.Delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True
Scenarios:=True
End Sub

But there are some rows in the sheet that i don't want anyone to b
able to delete.

Is there a way to run this so nobody can accidentally delete rows 1 t
8
 
F

Frank Kabel

Hi
one way: To prevent any deletion if row 1-8 are within the selection,
try

Sub DeleteMealItem()
If Intersect(Selection, Range("1:8")) Is Nothing Then
ActiveSheet.Unprotect
Selection.EntireRow.Delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
else
msgbox "Rows 1- 8 cannot be deleted"
end if
End Sub

Frank
 
T

thesteelmaker

Thank you very much Frank, that worked fine.

Now i wish i had chosen to do VBA on the course i am doing, it woul
have been more helpfull to me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top