VLOOKUP & SEARCH Functions

%3CLINGO-SUB%20id%3D%22lingo-sub-1810070%22%20slang%3D%22en-US%22%3EVLOOKUP%20%26amp%3B%20SEARCH%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1810070%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20way%20to%20combine%20a%20VLOOKUP%20with%20a%20SEARCH%20function%3F%20For%20example%2C%20in%20one%20column%20I%20have%20a%20bunch%20of%20unregulated%20comments%20referring%20to%20another%20facility%20and%2For%20city.%20I%20have%20a%20list%20of%20all%20possible%20cities%20and%20facilities%20but%20am%20not%20sure%20how%20to%20tell%20format%20the%20equation%20to%20say%20look%20in%20this%20string%20of%20words%20for%20a%20word%20that%20matches%20this%20table%20of%20cities.%20Is%20this%20possible%3F%20I%20can%20try%20to%20mock%20up%20the%20data%20if%20that%20would%20be%20helpful!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1810070%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1810137%22%20slang%3D%22en-US%22%3ERe%3A%20VLOOKUP%20%26amp%3B%20SEARCH%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1810137%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F842751%22%20target%3D%22_blank%22%3E%40Lou_117%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20would%20be%20helpful%20if%20you%20could%20provide%20an%20example%20of%20what%20the%20data%20look%20like%20and%20of%20what%20the%20expected%20result%20would%20be.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1812061%22%20slang%3D%22en-US%22%3ERe%3A%20VLOOKUP%20%26amp%3B%20SEARCH%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1812061%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BOf%20course!%20I%20attached%20a%20file%20with%20an%20example%20that%20the%20data%20comes%20in%20a%20very%20unregulated%20format%20as%20they%20are%20%22comments%22%20and%20then%20I%20listed%20all%20the%20cities%20within%20the%20state%20and%20all%20the%20hospitals.%20I%20did%20not%20list%20all%20the%20health%20systems%20for%20the%20overarching%20organization%20but%20did%20a%20few%20to%20give%20you%20an%20idea.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20hoping%20to%20have%20a%20formula%20that%20scans%20the%20%22comment%22%20field%20for%20any%20of%20the%20city%20names%2C%20and%20facilities%2C%20(I%20will%20list%20states%20so%20it%20can%20populate%20as%20%22Outside%20of%20State%22)%20but%20if%20a%20city%20is%20not%20found%20it%20returns%20%22%22%20so%20the%20cell%20appears%20blank.%20However%2C%20if%20the%20facility%20is%20listed%20but%20the%20city%20is%20now%2C%20it%20would%20be%20great%20if%20it%20could%20return%20%22Unknown%22.%20I%20hope%20this%20helps!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Is there a way to combine a VLOOKUP with a SEARCH function? For example, in one column I have a bunch of unregulated comments referring to another facility and/or city. I have a list of all possible cities and facilities but am not sure how to tell format the equation to say look in this string of words for a word that matches this table of cities. Is this possible? I can try to mock up the data if that would be helpful!

 

5 Replies
Highlighted

@Lou_117 

It would be helpful if you could provide an example of what the data look like and of what the expected result would be.

Highlighted

@Hans Vogelaar Of course! I attached a file with an example that the data comes in a very unregulated format as they are "comments" and then I listed all the cities within the state and all the hospitals. I did not list all the health systems for the overarching organization but did a few to give you an idea. 

 

I am hoping to have a formula that scans the "comment" field for any of the city names, and facilities, (I will list states so it can populate as "Outside of State") but if a city is not found it returns "" so the cell appears blank. However, if the facility is listed but the city is now, it would be great if it could return "Unknown". I hope this helps!

Highlighted

@Lou_117 

Thanks. In row 2 on Sheet 1, you have Beaumont as Goal 1 and Detroit as Goal 2.

Sheet2 has 9 instances of Beaumont Hospital, but none of them is in Detroit.

How does that work?

Highlighted

@Hans Vogelaar Sorry I was writing examples a little fast and just added a random city example to pull from. However, I have corrected that to reflect an example from the selections. 

Highlighted

@Lou_117 

Here is a solution using a custom VBA function GetLocation. It is entered in B2:C2 as an array formula, then filled down.

Function GetLocation(s As String)
    Dim wsh As Worksheet
    Dim i As Long
    Dim j As Long
    Dim parts() As String
    Dim rngC As Range
    Dim addr As String
    Dim rngF As Range
    Dim ret(1 To 2) As String
    ret(1) = "Unknown"
    ret(2) = "Unknown"
    Set wsh = Worksheets("Sheet2")
    parts = Split(s)
    For i = 0 To UBound(parts)
        Set rngC = wsh.Range("H:H").Find(What:=parts(i), _
            LookAt:=xlPart, MatchCase:=False)
        If Not rngC Is Nothing Then
            addr = rngC.Address
            Do
                For j = 0 To UBound(parts)
                    If j <> i Then
                        Set rngF = rngC.Offset(0, -3).Resize(1, 2).Find _
                            (What:=parts(j), LookAt:=xlPart, MatchCase:=False)
                        If Not rngF Is Nothing Then
                            ret(1) = rngF.Value
                            ret(2) = rngC.Value
                            GoTo ExitHere
                        End If
                    End If
                Next j
                Set rngC = wsh.Range("H:H").Find(What:=parts(i), _
                    After:=rngC, LookAt:=xlPart, MatchCase:=False)
                If rngC Is Nothing Then Exit Do
            Loop Until rngC.Address = addr
        End If
        Set rngF = wsh.Range("E:F").Find(What:=parts(i), _
            LookAt:=xlPart, SearchOrder:=xlByRows)
        If Not rngF Is Nothing Then
            ret(1) = rngF.Value
            addr = rngF.Address
            Do
                Set rngC = wsh.Range("H" & rngF.Row)
                For j = 0 To UBound(parts)
                    If j <> i Then
                        If UCase(rngC.Value) Like "*" & UCase(parts(j)) & "*" Then
                            ret(2) = rngC.Value
                            GoTo ExitHere
                        End If
                    End If
                Next j
                Set rngF = wsh.Range("E:F").Find(What:=parts(i), _
                    After:=rngF, LookAt:=xlPart, SearchOrder:=xlByRows)
                If rngF Is Nothing Then Exit Do
            Loop Until rngF.Address = addr
        End If
    Next i
ExitHere:
    GetLocation = ret
End Function

See the attached version.