#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Three Cases

Hi,

Im trying to write code so that if i

1) Insert a value in col A a row is inserted below
2) If i then go back and delete this value the row below is deleted
3) If I go back and change the value the no of rows remain

With the code below rows are inserted in all three cases,
many thanks for help



Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo ws_exit:
With Target
If .Column = 1 Then
If .Cells.Count = 1 Then
.Offset(1).EntireRow.Insert xlShiftDown
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Three Cases

Teresa,

Stick to one thread it makes life simpler to see what has already gone down.

This is difficult, how is the code supposed to know that a row has been
inserted by this code, or that a cell has already been changed. One way
would be to have a column with a value in there, which can handle conditions
1 and 3, but not 2. Best to select both rows to delete that.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo ws_exit:
With Target
If .Column = 1 Then
If .Cells.Count = 1 Then
If .Offset(0, 1).Value < "Upd" Then
.Offset(0, 1).Value = "Upd"
.Offset(1).EntireRow.Insert xlShiftDown
.Offset(1, 1).Value = "Insert"
End If
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub


--
HTH

Bob Phillips

"teresa" wrote in message
...
Hi,

Im trying to write code so that if i

1) Insert a value in col A a row is inserted below
2) If i then go back and delete this value the row below is deleted
3) If I go back and change the value the no of rows remain

With the code below rows are inserted in all three cases,
many thanks for help



Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo ws_exit:
With Target
If .Column = 1 Then
If .Cells.Count = 1 Then
.Offset(1).EntireRow.Insert xlShiftDown
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub





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
Formula for Cases=144 * # of Cases + Pieces Inventory Formula Excel Discussion (Misc queries) 2 December 29th 09 09:09 PM
repetition cases Omar Excel Discussion (Misc queries) 2 May 9th 07 09:17 PM
two cases for countif joi2 Excel Worksheet Functions 1 November 8th 05 02:07 PM
Cases Carl Excel Programming 1 October 20th 04 02:10 PM
combobox cases Hannu Rantala Excel Programming 4 April 6th 04 05:40 AM


All times are GMT +1. The time now is 04:12 PM.

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"