There's a couple of things that concern me here.
First thing: If you put this code in the Worksheet_Change event, it will
delete entire rows every time an entire row is selected. Is this what you
want?
Second thing: Multiple selections will create ".Areas" on the sheet if the
selected rows are not contiguous. This necessitates deleting rows in reverse
order (last to first) so as they're deleted an error is avoided, and the
desired rows are the ones actually deleted. For example, if your user selects
rows 3, 5, and 7 and row3 is deleted first then rows 5 and 7 now become rows
4 and 6 respectively. This causes what used to be row 6 to be deleted next as
it's now row5 & next in line, ..causing the cycle to repeat, making your
original row7 eventually in the row5 position. As you may guess, row7 (now
row5) doesn't get deleted because row9, which does get deleted, is now in
row7 position.
Going in reverse order deletes row7 first, leaving rows 5 and 3 correctly
positioned, and next in line respectively. This requires more code, and the
use of a For..Next loop.
If, as you say, some of the cells in the rows are locked then don't allow
them to be selected. This makes things easier to code. You could use a
control (button) for users to fire the procedure with after they select cells
in the rows to delete. You wouldn't need an If..Then construct either. The
code would simply be something like:
With ActiveSheet
.Unprotect
.Range(Selection.Address).EntireRow.Delete
.Protect
End With
This lets Excel handle the issue for getting the right rows, and it's way
lots faster than using a For..Next loop or If..Then construct.
HTH
Regards,
Garry