Re: June/July 2008 Challenge of the Month
Did not know about the posts and threads before creating this UDF so here is another variation.
I really like the simple solution though:
=LOOKUP(2^15,SEARCH(D$2:D$11,A2),E$2:E$11))
Wow!
'---------------------------------------------------------------------------------------
' Module : UDF
' DateTime : 7/8/2008 14:02
' Author : Nenad Stojkovski
' Purpose : MRExcel Challange June 2008
'---------------------------------------------------------------------------------------
Option Explicit
'---------------------------------------------------------------------------------------
' Procedure : us of the UDF: =IDAssigned(A2)
' Purpose : Find the color in the text and assign the Name of the person from the table to the right
'---------------------------------------------------------------------------------------
'
Public Function IDAssigned(CellRef As Range)
Dim cCell As Range
Dim strTestVal As String
Dim Bullpen As String
Dim varFindRef As Variant
Dim wks As Worksheet
Dim rngLookupRange As Range
Dim SrchVals As Range
Set wks = ThisWorkbook.Worksheets("Sheet1")
'Dynamic Range for the Colors and Assigned map
Set SrchVals = _
wks.Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
'Check if the Phrases is blank
If Len(CellRef) = 0 Then
IDAssigned = "No Match"
Exit Function
End If
'Loop through colors values
For Each cCell In SrchVals.Cells
strTestVal = CStr(cCell.Value)
If Len(CellRef.Value) <> 0 Then
'List ref cell is not blank, so test the cell
varFindRef = InStr(1, CellRef, strTestVal)
If varFindRef > 0 Then
Bullpen = cCell.Offset(0, 1).Value
GoTo foundit
End If
End If
Next cCell
foundit:
If Bullpen = "" Then
IDAssigned = "No Match"
Else
IDAssigned = Bullpen
End If
End Function