Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default prevent row insert in a range of rows

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent Insert Row and Delete Row from Menu Sherry Excel Discussion (Misc queries) 4 August 14th 08 06:54 PM
I want to prevent a formula from being affected by insert line StiDude Excel Worksheet Functions 10 May 24th 07 09:22 PM
How can I insert and delete rows within a locked cell range column Gordon Cole Excel Worksheet Functions 0 October 1st 06 11:30 AM
prevent additional rows accesspro Excel Discussion (Misc queries) 2 March 11th 06 02:06 AM
Prevent adding rows Rene[_3_] Excel Programming 1 May 7th 04 06:07 AM


All times are GMT +1. The time now is 11:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"