A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Like this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldValue As String
Dim NewValue As String
If Target.CountLarge > 1 Then Exit Sub
If Intersect(Target, Range("J:K")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub
Application.EnableEvents = False
On Error GoTo ExitSub
NewValue = Target.Value
Application.Undo
OldValue = Target.Value
If OldValue = "" Then
Target.Value = NewValue
ElseIf InStr(1, vbLf & OldValue & vbLf, vbLf & NewValue & vbLf) = 0 Then
Target.Value = OldValue & vbLf & NewValue
Else
NewValue = Replace(vbLf & OldValue & vbLf, vbLf & NewValue & vbLf, vbLf)
If Left(NewValue, 1) = vbLf Then
NewValue = Mid(NewValue, 2)
End If
If Right(NewValue, 1) = vbLf Then
NewValue = Left(NewValue, Len(NewValue) - 1)
End If
Target.Value = NewValue
End If
ExitSub:
Application.EnableEvents = True
End Sub