PDA

View Full Version : Drop down multi select while also changing what is shown in the cell



Jon H
08-12-2021, 08:41 AM
So I am working on a form that has a drop down that shows the details in the drop down but when you select it you only see the department code. I have been asked to change it to where you can choose multiple departments and I cannot get the change from the details to department code to work after the first selection. Below is my code and some screenshots if my description isn't quite up to par.
28830


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$C$8" 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
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = False
selectedNa = Target.Value
If Target.Column = 3 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("droplist"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
selectedNa = Target.Value
If Target.Column = 3 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("CostsC"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
Application.EnableEvents = True
End Sub