ManUBlueJay
Active Member
- Joined
- Aug 30, 2012
- Messages
- 302
- Office Version
- 2016
- Platform
- Windows
I am trying to run a macro that would allow multiple selections in a excel data validation list.
I would have thought this code would work but it doesnt. It exits the sub before adding in the line with the comma.
I would have thought this code would work but it doesnt. It exits the sub before adding in the line with the comma.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("J3:J10000")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) 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
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub