I am working on a spreadsheet where I need the dropdown list to display the full description but once selected to only display the relevant code for that selection. I have following VBA Code that allows me to run this without any issue.
Private Sub Worksheet_Change(ByVal Target As Range)
Category_Description = Target.Value
If Target.Column = 4 Then
Category_Num = Application.VLookup(Category_Description, Worksheets("Sheet2").Range("EquipmentCategories"), 2, False)
If Not IsError(Category_Num) Then
Target.Value = Category_Num
End If
End If
End Sub
However, I would like to be able to do this as a multiple selection drop down list to allow for multiple categories to be chosen. Separately from the above code I can make this work with the following VBA Code.
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.Column = 4 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 = True
End Sub
Does anyone know what modifications to the two codes I would need to make in order to combine them and allow for the multiple selection to work with the VLookup?
Private Sub Worksheet_Change(ByVal Target As Range)
Category_Description = Target.Value
If Target.Column = 4 Then
Category_Num = Application.VLookup(Category_Description, Worksheets("Sheet2").Range("EquipmentCategories"), 2, False)
If Not IsError(Category_Num) Then
Target.Value = Category_Num
End If
End If
End Sub
However, I would like to be able to do this as a multiple selection drop down list to allow for multiple categories to be chosen. Separately from the above code I can make this work with the following VBA Code.
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.Column = 4 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 = True
End Sub
Does anyone know what modifications to the two codes I would need to make in order to combine them and allow for the multiple selection to work with the VLookup?