I try to VLOOKUP but it can only returns 1 value. I want my result to return multiple email and my lookup value is the multiple names in one cell. The first cell is the value I want to match with my lookup table.
Below is my lookup table where everybody email is here, but how I achieve the result like [email protected];[email protected], so I can just automate a reminder email in VBA using lookup emails earlier? How I can achieve this?
I also got this error when I debug, I cannot get the selected emails
Sub getEmails()
Dim toNames As Range
Set toNames = Range("J3:J500") ' names input by user
Dim names As Range
Set names = Range("Email!B3:C25") ' names range from lookup table from different worksheet
Dim splitNames
splitNames = Split(toNames, ",")
Dim selectedEmails As String
For i = 0 To UBound(splitNames)
findRange = names.Find(What:=splitNames(i), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
' if match found, get the email and store to selected emails variable
If Not findRange Is Nothing Then
selectedEmails = selectedEmails & Range("B" & findRange.Row) & ";"
End If
Next i
'output emails
Range("Q3:Q500") = selectedEmails
End Sub
Pui Kuan, Eric
is the input field,Split
it into individual names, do VLookups on each of the individual names, and concatenate the results. – YowE3K