When I am currently applying this code to allow for multiple selection in my dropdown menu I want it to only affect Column E. However, it have an affect on the whole sheet. Can some body please help me to fix this, so I can isolate the code?
Private Sub Worksheet_Change(ByVal Target As Range)
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
Dim AffectedCells As Range
Set AffectedCells = Intersect(Me.Range("$E$2:$E$40"), Target)
If Target Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub••••ˇˇˇˇ
For example when I write in Column D and wish to overwrite it. It just makes a conjunction between what previously was in the box and the newly added information.
Thanks a lot.