View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
[email protected] britwiz@hotmail.com is offline
external usenet poster
 
Posts: 27
Default insert a row with enter on a specific cell


Oakie wrote:
I am using excell 2003
I am trying to insert a row with a border on a protected worksheet, so that
I can tab or enter through the unlocked cells but when I get to a specific
cell it will add a row to continue with the smae line above.
EX.
A1:A3 , C1:C3 and E1:E3 all have borders around each cell and are unlocked.
I can tab from A1,A2,A3,C1 etc. or Enter A1,C1,E1,A2 etc...I need to insert
a new row if I hit enter at A3,C3 or E3, so i can contiue on with the
bordered chart ive made.
So the border will now be A1:B3 and everything else has shifted down to
D1:D3 and so on.
I hope this makes sence to someone. thanks in advanced


Hi Oakie

I'm not entirely sure of your description as, if you insert a row,
everything does indeed move down so I don't see how A1:A3 becomes A1:B3
or C1:C3 becomes D1:D3.

However, based on your description rather than your ranges, try this in
the sheet's code (right-click the sheet's tab View Code and paste):

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue
If Target.Row = 3 And _
Target.Borders(xlEdgeBottom).LineStyle = xlContinuous Then
Application.EnableEvents = False
ActiveSheet.Unprotect
With Target
myValue = .Value
.Value = ""
.EntireRow.Insert
.Offset(-1, 0) = myValue
End With
ActiveSheet.Protect
Application.EnableEvents = True
End If
End Sub

The above code will increase all three "charts" by one row.

If you only want to amend the current "chart" try this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue
If Target.Row = 3 And _
Target.Borders(xlEdgeBottom).LineStyle = xlContinuous Then
Application.EnableEvents = False
ActiveSheet.Unprotect
Target.Borders(xlEdgeBottom).LineStyle = xlNone
With Target.Offset(1, 0)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
End With
ActiveSheet.Protect
Application.EnableEvents = True
End If
End Sub

Regards

Steve