try:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Cells.Count = 1 And Not Intersect(Target, Range("$A$14, $A$30, $A$40, $A$50")) Is Nothing Then
If Intersect(Cells.SpecialCells(xlCellTypeAllValidation), Target) Is Nothing Then
GoTo Exitsub
ElseIf Target.Value = "" Then
GoTo Exitsub
Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
Target.Value = Newvalue
If Oldvalue <> "" Then
If Newvalue <> "" Then
If InStr(1, Oldvalue, vbLf & Newvalue & vbLf) > 0 Then
Oldvalue = Replace(Oldvalue, Newvalue & vbLf, "") ' If it's in the middle with comma
Target.Value = Oldvalue
GoTo jumpOut
End If
If Left(Oldvalue, Len(Newvalue & vbLf)) = Newvalue & vbLf Then
Oldvalue = Replace(Oldvalue, Newvalue & vbLf, "") ' If it's at the start with comma
Target.Value = Oldvalue
GoTo jumpOut
End If
If Right(Oldvalue, Len(vbLf & Newvalue)) = vbLf & Newvalue Then
Oldvalue = Left(Oldvalue, Len(Oldvalue) - Len(vbLf & Newvalue)) ' If it's at the end with a comma in front of it
Target.Value = Oldvalue
GoTo jumpOut
End If
If Oldvalue = Newvalue Then ' If it is the only item in string
Oldvalue = ""
Target.Value = Oldvalue
GoTo jumpOut
End If
Target.Value = Oldvalue & vbLf & Newvalue
End If
jumpOut:
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
ps. This original line doesn't do what it's intended to:
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
because when target is a single cell the whole sheet is looked at so it only tests if the sheet contains at least one cell with data validation in it.