+ Reply to Thread
Results 1 to 5 of 5

Return Value from string if it Match is Found in Range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Return Value from string if it Match is Found in Range

    I'm looking for a function to return the values from a string that exists in a Range.
    If a match is found it should should be returned proceeded by a value 1 column next to the string.

    The attachment will make clear what I mean.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Return Value from string if it Match is Found in Range

    Maybe:

    Sub Jonathan78()
    Dim w As String
    Dim x As Long
    Dim y As Long
    Dim z As String
    z = ""
    For x = 24 To 27
    w = Cells(x, "A") & "/"
        For y = 4 To 20
            If Cells(x, "B").Value Like "*" & Cells(y, "B").Value & "*" Then
                z = w & Cells(y, "B").Value & ","
            End If
            w = z
        Next y
    Cells(x, "C") = w
    Cells(x, "C").Replace ",", ", " & Cells(x, "A").Value & "/"
    If Len(Cells(x, "C")) > 3 Then
    Cells(x, "C") = Cells(x, "A") & "/" & Left(Cells(x, "C"), Len(Cells(x, "C")) - 5)
    Else
    Cells(x, "C") = Cells(x, "A") & "/" & Cells(x, "C")
    End If
    If Len(Cells(x, "C")) < 4 Then Cells(x, "C") = ""
    z = ""
    Next x
    End Sub
    Last edited by JOHN H. DAVIS; 02-17-2015 at 08:33 AM.

  3. #3
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Return Value from string if it Match is Found in Range

    Thanks John, this seems to work.
    How do I translate this in an Function?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Return Value from string if it Match is Found in Range

    H24:

    =SplitList(A24,B24,$B$3:$B$20)

    and fill down
    Function SplitList(ByVal pref As String, txt As String, List As Range) As String
        Dim myList As String, m As Object
        myList = Join(Filter(Evaluate("transpose(if(" & List.Address(external:=True) & _
        "<>""""," & List.Address(external:=True) & ",char(2)))"), Chr(2), 0), "|")
        With CreateObject("VBScript.RegExp")
            .Pattern = myList: .Global = True
            For Each m In .Execute(txt)
                SplitList = SplitList & IIf(SplitList <> "", ", ", "") & pref & "/" & m.Value
            Next
        End With
    End Function

  5. #5
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Return Value from string if it Match is Found in Range

    Thanks again Jindon, it works like a charm!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Search for String in Range, If Match, Return Matching Cell Value
    By ryanb909 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-21-2013, 02:27 AM
  2. [SOLVED] IF range of cells contains string of text, return contents of cell where string is found
    By nobodyukno in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-03-2013, 09:56 AM
  3. [SOLVED] Search for a string within a cell, if found, return value of 1
    By brookenovak in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2013, 07:39 PM
  4. Replies: 3
    Last Post: 04-12-2010, 02:33 AM
  5. Replies: 5
    Last Post: 10-11-2008, 04:01 PM

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