I am currently using the below code to populate a (userform) listbox with items on loan based on a person's name(Column B). I need to also include the Item ID number as a reference for further functions. I am wondering what is the best approach to return two values from a row (Item name(Column C) and ID number(Column L)) based on a reference value (Person's name) into a listbox.
Private Sub cboName_Change()
Me.ListItem.Clear
Dim ws As Worksheet
Dim i As Range
Set ws = Worksheets("Loans")
With ws
LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
End With
Set i = ws.Range("B1:A" & LastRow)
With i
Set c = .Find(cboName.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Set c = .FindNext(c)
ListItem.AddItem .Cells(c.Row, 3).Value
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
If this question is very similar to others already asked (always getting in trouble for that), any direction would be appreciated - I may just need some context (very new at coding). Thanks!