michaeltsmith93
Board Regular
- Joined
- Sep 29, 2016
- Messages
- 83
For the life of me, I can't figure out why this isn't working. It gives me a #VALUE error.
I'm using ActiveSheet because I'll put it on a number of different sheets, and I don't want to have to add a field in the function for that.
LookupRange is designed to find the last row with data in it on ActiveSheet.
My lookup values begin in B5 and extend indefinitely, and the desired matches are in Column O (15th column).
I'm using ActiveSheet because I'll put it on a number of different sheets, and I don't want to have to add a field in the function for that.
LookupRange is designed to find the last row with data in it on ActiveSheet.
My lookup values begin in B5 and extend indefinitely, and the desired matches are in Column O (15th column).
Code:
Function EmailConcat(LookupValue As String)
Application.Volatile
Dim i As Long
Dim Result As String
Dim LookupSheet As Worksheet
Dim LookupRange As Range
Set LookupSheet = Application.ActiveSheet
LookupRange = LookupSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
For i = 5 To LookupRange.Rows.Count
If LookupSheet.Cells(i, 2) = LookupValue Then
Result = Result & LookupSheet.Cells(i, 15) & "; "
End If
Next i
EmailConcat = Left(Result, Len(Result) - 2)
End Function