View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rogerio Takejame Rogerio Takejame is offline
external usenet poster
 
Posts: 2
Default prevent row insert in a range of rows

Tricky question... You can't protect the sheet because if you do it you won't
be able to insert rows anywhere. Well, you can avoid the selection of the
header and the summary by the user so he can't insert rows there.
Start by naming the header range as header and the summary range as summary,
using InsertName. Then copy and paste the code below to your worksheet code
area in the VBA editor. If you try to select a header cell the code will send
the cursor to the first row after the header. Similarly, if you try to select
a summary row, the code will send the cursor to the first row before the
summary.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Set head = ActiveWorkbook.Names("header").RefersToRange
Set summ = ActiveWorkbook.Names("summary").RefersToRange
If Target.Row = head.Cells(1, 1).Row And Target.Row <=
head.Cells(head.Rows.Count, 1).Row Then
head.Cells(head.Rows.Count, Target.Column).Offset(1, 0).Select
End If
If Target.Row = summ.Cells(1, 1).Row And Target.Row <=
summ.Cells(summ.Rows.Count, 1).Row Then
summ.Cells(1, Target.Column).Offset(-1, 0).Select
End If
End Sub

--
Rogerio Takejame
Americana - Sao Paulo - Brazil


"pcorbani" wrote:

I have a worksheet with header text in rows 1 thru 5 and summary data in last
4 rows (variable row number dependent on number of data rows). How can I
prevent users from inserting rows in the header and summary sections, but
allow them to insert rows after row 6 and before the summary rows?