I have a list I have created under data validation. I need the list to allow multiple selections with the new selection beginning on a new line. I have watched You Tube Video's and played around but can't seem to get this code right. I am a novice excel user.
When I use the data validation list now I get a pop up that say's "Variable not defined", and highlights the word NewValue in my code. Help Please!!
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oldVal As String
Dim newVal As String
On Error GoTo Exitsub
If Target.Column = 3 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 & vbNewLine & NewValue
Else
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
When I use the data validation list now I get a pop up that say's "Variable not defined", and highlights the word NewValue in my code. Help Please!!
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oldVal As String
Dim newVal As String
On Error GoTo Exitsub
If Target.Column = 3 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 & vbNewLine & NewValue
Else
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub