Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add & delete row base on location of selected row

Status
Not open for further replies.

maximas

Programmer
Nov 29, 2002
40
US
I have a worksheet, but I want only parts of the worksheet be able to add or delete rows. If I select the cell(1,1) the user can use macro to insert line. If I select (5,1) the user can not use macro to insert line . Example:
A B C D E
1
2
3
4 protected from adding or deleting this row
5 protected from adding or deleting this row
6 protected from adding or deleting this row
7
8

How could I do that!
 
Try this:

Select the rows you want to protect and assign a range name "ProtectMe"

Then put this macro code in the worksheet module:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
  If Intersect(Target, Range("ProtectMe")) Is Nothing Then
    ActiveSheet.Unprotect
  Else
    ActiveSheet.Protect
  End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top