+ Reply to Thread
Results 1 to 10 of 10

Finding strings in vlookup value, embedded in larger strings within the table array

Hybrid View

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    London, England
    MS-Off Ver
    Excel for Mac (16.25)
    Posts
    42

    Finding strings in vlookup value, embedded in larger strings within the table array

    I need to do a vlookup that takes a string from one cell and then tries to find that string (embedded in a larger string) in the table array

    Essentially I imagine this involves the FIND funtion at some point.

    Attached is an incredibly simplified example of what I’m looking for.

    Thanks in advance, for your help
    Attached Files Attached Files

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    Try this:
    Formula: copy to clipboard
    =INDEX($G$3:$G$10,MATCH(MIN(SEARCH(B3,$F$3:$F$10&B3)),SEARCH(B3,$F$3:$F$10&B3),0))


    Comfirm with crtrl+shift+enter (not just enter)
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    10-18-2011
    Location
    London, England
    MS-Off Ver
    Excel for Mac (16.25)
    Posts
    42

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    Hi,

    Thanks for the fast response. It works perfect on the example.

    Apologies but I should have provided a better example that was truer to my specific problem.

    Attached, is my updated example to reflect my real problem (im not trying to return a number so SEARCH() doesn't work)

    Again, help is greatly appreciated.

    Kind regards,
    Zak

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    1. Comfirm formula with CSE
    2. you can achive that by VBA code

  5. #5
    Registered User
    Join Date
    10-18-2011
    Location
    London, England
    MS-Off Ver
    Excel for Mac (16.25)
    Posts
    42

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    1. I was using CSE incorrectly. Apologies.
    2. Is there a separate forum area for requesting help with VBA code?

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    It's OK staying here, hope someone can figure way out

  7. #7
    Registered User
    Join Date
    10-18-2011
    Location
    London, England
    MS-Off Ver
    Excel for Mac (16.25)
    Posts
    42

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    Okay great.

    For anyone visiting with VBA knowledge, please see my most recently uploaded example.

    Basically -

    I need my existing Index/Search formula to use an 'alrea.dy exists in the cell above' logic when grabbing a value from column G and putting it in column C(see example, attached)

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    Here, try this:

    Sub Partial_lookup()
    Dim ws As Worksheet
    Dim rng1 As Range, rng2 As Range
    Dim LastRng1 As Long, LastRng2 As Long
    Dim i As Integer
    
    Set ws = Sheets("Sheet1")
    LastRng1 = Range("B65536").End(xlUp).Row
    LastRng2 = Range("F65536").End(xlUp).Row
    
    Set rng1 = ws.Range("B3:B" & LastRng1)
    rng1.Offset(0, 1).ClearContents
    
    For Each Rng In rng1
        For i = 1 To LastRng2
        
        If InStr(ws.Range("F2").Offset(i), Rng) > 0 Then
            If Application.WorksheetFunction.CountIf(rng1.Offset(0, 1), ws.Range("F2").Offset(i, 1)) = 0 Then
            Rng.Offset(0, 1) = ws.Range("F2").Offset(i, 1): Exit For
            End If
        End If
        Next i
    Next Rng
    
    End Sub

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,059

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    Only be careful: It looks for exact string.
    In your original example there was criteria Authorise Customer Bill Invoice Adjustment with space at the end.
    So it won't find it in Filenames.

    You can ignore spaces with something like this:

    Sub Partial_lookup()
    Dim ws As Worksheet
    Dim rng1 As Range, rng2 As Range
    Dim LastRng1 As Long, LastRng2 As Long
    Dim i As Integer
    
    Set ws = Sheets("Sheet1")
    LastRng1 = Range("B65536").End(xlUp).Row
    LastRng2 = Range("F65536").End(xlUp).Row
    
    Set rng1 = ws.Range("B3:B" & LastRng1)
    rng1.Offset(0, 1).ClearContents
    
    For Each Rng In rng1
        For i = 1 To LastRng2
        
        If InStr(Trim(ws.Range("F2").Offset(i)), trim(Rng)) > 0 Then
            If Application.WorksheetFunction.CountIf(rng1.Offset(0, 1), ws.Range("F2").Offset(i, 1)) = 0 Then
            Rng.Offset(0, 1) = ws.Range("F2").Offset(i, 1): Exit For
            End If
        End If
        Next i
    Next Rng
    
    End Sub
    Edit: Used Trim as JP suggested
    Last edited by zbor; 12-21-2012 at 04:26 AM.

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Finding strings in vlookup value, embedded in larger strings within the table array

    using trim might be safer. btw for the original question I reckon vlookup with a wildcard would be easier
    =vlookup("*"&b3&"*",$f$3:$g$10,2,false)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1