Hi there,
I am currently using a VBA code on numerous tabs of my spread sheet (that I sourced from online), which allows the Excel user to select multiple options from a drop-down list (in a specific column/s), so that each value they select is then separated by a comma. I am a teacher and we needed to enable users to select multiple student names from a data validation list, to receive particular awards. I now want to know how to adjust the code so that instead of making this applicable to any number of columns with these drop-down lists, I can select a single cell and its drop-down list. The reason for this need is because the other cells in the column only require one option to be selected, but this specific cell requires FOUR options. I have pasted the current code I use below, which applies to the whole column D (4). Could anyone please suggest how I change it to only apply to cell D9? Thank you!
Option Explicit
' Developed by Contextures Inc.
' www.contextures.com
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim lUsed As Long
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 4 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
lUsed = InStr(1, oldVal, newVal)
If lUsed > 0 Then
If Right(oldVal, Len(newVal)) = newVal Then
Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
Else
Target.Value = Replace(oldVal, newVal & ", ", "")
End If
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
Bookmarks