Hello,
I am trying to create a code that will let me make multiple selections in a list, and put the selection in the next row down in the same column. My code works for selecting multiple values, but it puts them all in the same cell. Any help is greatly appreciated.
CODE:
I am trying to create a code that will let me make multiple selections in a list, and put the selection in the next row down in the same column. My code works for selecting multiple values, but it puts them all in the same cell. Any help is greatly appreciated.
CODE:
Code:
Private Sub Worksheet_Change(ByVal Target As Range) Dim xRng As Range
Dim xValue1 As String
Dim xValue2 As String
lastrow = Workbooks("Data Sheet.xlsm").Worksheets("Log").Cells(Rows.Count, "A").End(xlUp).Row
If Target.Count > 1 Then Exit Sub
On Error Resume Next
Set xRng = Cells.SpecialCells(xlCellTypeAllValidation)
If xRng Is Nothing Then Exit Sub
Application.EnableEvents = False
If Not Application.Intersect(Target, xRng) Is Nothing Then
xValue2 = Target.Value(lastrow + 1)
Application.Undo
xValue1 = Target.Value(lastrow + 1)
Target.Value(lastrow + 1) = xValue2
If xValue1 <> "" Then
If xValue2 <> "" Then
If xValue1 = xValue2 Or _
InStr(1, xValue1, ", " & xValue2) Or _
InStr(1, xValue1, xValue2 & ",") Then
Target.Value(lastrow + 1) = xValue1
Else
Target.Value(lastrow + 1) = xValue1 & ", " & xValue2
End If
End If
End If
End If
Application.EnableEvents = True
End Sub