I have a Worksheet_Change module in a worksheet, which allows me to select multiple, comma separated, non-repeatable numbers from a dropdown list, displayed in a single cell, e.g $C$4 will read "00004, 00006, 00009" etc. This is the code (which I copied verbatim from https://trumpexcel.com/select-multiple-items-drop-down-list-excel/#VBA-Code-to-allow-Multiple-Selections-in-a-Drop-down-List-without-repetition - I only changed the "Target" cell):
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com
'To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = False
On Error GoTo Exitsub
If Target.Address = "$K$9" 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
End If
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
The problem - which I know I am not the first to have, and I've looked at several other solutions but none of them seem to work - is that I need the sheet to be protected. But when I protect it, the code no longer works, and I can only select one nr per cell.
I've tried turning off the EnableEvents and then adding the "unprotect" and "protect" lines in various places, but it makes 0 difference, it's as if the code completely ignores those lines, no matter where I put them. But the sheet HAS to be protected. There will be several people working with it, and there are very long and complicated formulas in other cells that I cannot afford them messing with. Any suggestions?