Hi,
I have a spreadsheet where I have the cell range E4:J72 of which each cell contains the same reference to data validation. I would like to be able to be able to select 2 or 3 items from my list.
I have been trying to use the code created by Contextures.com but cannot seem to get it to work...
I have not used macros much, yet this looks less complex than others...I think I know just enough to be dangerous...
Thank you in advance for the help!
Kenn
I have a spreadsheet where I have the cell range E4:J72 of which each cell contains the same reference to data validation. I would like to be able to be able to select 2 or 3 items from my list.
I have been trying to use the code created by Contextures.com but cannot seem to get it to work...
I have not used macros much, yet this looks less complex than others...I think I know just enough to be dangerous...
Rich (BB code):
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 = 5 _
And Target.Row >= 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
Thank you in advance for the help!
Kenn
Last edited by a moderator: