Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCell As Range
Dim rDelete As Range
'Original
If Not Intersect(Target, Range("ToolingData_Table_End").EntireColumn) Is Nothing Then
Application.EnableEvents = False
For Each rCell In Intersect(Target, Range("ToolingData_Table_End").EntireColumn).Cells
If rCell.Row = Range("ToolingData_Table_End").Row - 1 Then
If Len(rCell.Value) > 0 Then
Range("ToolingData_Table_End").EntireRow.Insert
Else
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
ElseIf Len(rCell.Value) = 0 Then
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
Next rCell
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
Application.EnableEvents = True
End If
'New
If Not Intersect(Target, Range("ToolingData_Table_Start").EntireColumn) Is Nothing Then
Application.EnableEvents = False
For Each rCell In Intersect(Target, Range("ToolingData_Table_Start").EntireColumn).Cells
If rCell.Row = Range("ToolingData_Table_Start").Row - 1 Then
If Len(rCell.Value) > 0 Then
Range("ToolingData_Table_Start").Offset(-1, 0).EntireRow.Insert
Else
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
ElseIf Len(rCell.Value) = 0 Then
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
Next rCell
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
Application.EnableEvents = True
End If
End Sub