+ Reply to Thread
Results 1 to 4 of 4

Comparison - Strings and Arrays

  1. #1
    jbtenor1
    Guest

    Comparison - Strings and Arrays

    I'm posting this again in the hopes that someone has an answer. I am not
    having any luck with the 'Find' or 'Search' functions.

    I am wanting to take a delimited string in a cell (B2) containing multiple
    data elements and compare it to an array ($AA$2:$AA$10), then have the
    matching data from the cell trimmed and displayed in a neighboring cell (C2).
    I believe the best result would be for it to return the value(s) that match
    one or more of the data elements in $AA$2:$AA$10.

    From the example below, if I could have B2 contain the string, C2 would
    contain the function that gives me the result of the match. For instance,
    $AA$2:$AA$10 contains:

    ACLEMON
    BDUFOUR
    BLANGLI
    DDILUCE
    DWELLS
    ESCOTT
    KRENKER
    THUMENI
    WROCHES

    If B2 contains:

    MROMANO|MTELLIG|JGURECK|MWOLK|LGAZDA|GVANBUH|CSHOAF|STILLER|RVERBIC|DSTEPHE|BLANGLI

    C2 should return a result of BLANGLI. If there is more than one piece of
    matching data, then it would be great if C2 could display the multiple items
    in a new pipe-delimited string. Then, I want to do this for the remaining
    cells (B3 to B146) in a successive list. Any advice on accomplishing this is
    GREATLY appreciated. Thanks in advance!

    Jeff Bloomer
    Business/Reporting Analyst
    Standard Register
    www.standardregister.com

  2. #2
    Toppers
    Guest

    RE: Comparison - Strings and Arrays

    Try this UDF

    in C2 put =findstrings(B2) and copy down

    Function findStrings(ByVal srchstr As String)
    Set comprng = Range("aa2:aa10")
    findstr = ""
    For i = 2 To 10
    n = InStr(1, srchstr, comprng(i), vbTextCompare)
    If n <> 0 Then findstr = findstr & Mid(srchstr, n, Len(comprng(i))) & "|"
    Next i
    If findstr <> "" Then
    findStrings = Left(findstr, Len(findstr) - 1)
    Else
    findStrings = ""
    End If
    End Function


    "jbtenor1" wrote:

    > I'm posting this again in the hopes that someone has an answer. I am not
    > having any luck with the 'Find' or 'Search' functions.
    >
    > I am wanting to take a delimited string in a cell (B2) containing multiple
    > data elements and compare it to an array ($AA$2:$AA$10), then have the
    > matching data from the cell trimmed and displayed in a neighboring cell (C2).
    > I believe the best result would be for it to return the value(s) that match
    > one or more of the data elements in $AA$2:$AA$10.
    >
    > From the example below, if I could have B2 contain the string, C2 would
    > contain the function that gives me the result of the match. For instance,
    > $AA$2:$AA$10 contains:
    >
    > ACLEMON
    > BDUFOUR
    > BLANGLI
    > DDILUCE
    > DWELLS
    > ESCOTT
    > KRENKER
    > THUMENI
    > WROCHES
    >
    > If B2 contains:
    >
    > MROMANO|MTELLIG|JGURECK|MWOLK|LGAZDA|GVANBUH|CSHOAF|STILLER|RVERBIC|DSTEPHE|BLANGLI
    >
    > C2 should return a result of BLANGLI. If there is more than one piece of
    > matching data, then it would be great if C2 could display the multiple items
    > in a new pipe-delimited string. Then, I want to do this for the remaining
    > cells (B3 to B146) in a successive list. Any advice on accomplishing this is
    > GREATLY appreciated. Thanks in advance!
    >
    > Jeff Bloomer
    > Business/Reporting Analyst
    > Standard Register
    > www.standardregister.com


  3. #3
    Toppers
    Guest

    RE: Comparison - Strings and Arrays

    Sorry

    For i = 2 To 10

    should be

    For i = 1 To 9



    "Toppers" wrote:

    > Try this UDF
    >
    > in C2 put =findstrings(B2) and copy down
    >
    > Function findStrings(ByVal srchstr As String)
    > Set comprng = Range("aa2:aa10")
    > findstr = ""
    > For i = 2 To 10
    > n = InStr(1, srchstr, comprng(i), vbTextCompare)
    > If n <> 0 Then findstr = findstr & Mid(srchstr, n, Len(comprng(i))) & "|"
    > Next i
    > If findstr <> "" Then
    > findStrings = Left(findstr, Len(findstr) - 1)
    > Else
    > findStrings = ""
    > End If
    > End Function
    >
    >
    > "jbtenor1" wrote:
    >
    > > I'm posting this again in the hopes that someone has an answer. I am not
    > > having any luck with the 'Find' or 'Search' functions.
    > >
    > > I am wanting to take a delimited string in a cell (B2) containing multiple
    > > data elements and compare it to an array ($AA$2:$AA$10), then have the
    > > matching data from the cell trimmed and displayed in a neighboring cell (C2).
    > > I believe the best result would be for it to return the value(s) that match
    > > one or more of the data elements in $AA$2:$AA$10.
    > >
    > > From the example below, if I could have B2 contain the string, C2 would
    > > contain the function that gives me the result of the match. For instance,
    > > $AA$2:$AA$10 contains:
    > >
    > > ACLEMON
    > > BDUFOUR
    > > BLANGLI
    > > DDILUCE
    > > DWELLS
    > > ESCOTT
    > > KRENKER
    > > THUMENI
    > > WROCHES
    > >
    > > If B2 contains:
    > >
    > > MROMANO|MTELLIG|JGURECK|MWOLK|LGAZDA|GVANBUH|CSHOAF|STILLER|RVERBIC|DSTEPHE|BLANGLI
    > >
    > > C2 should return a result of BLANGLI. If there is more than one piece of
    > > matching data, then it would be great if C2 could display the multiple items
    > > in a new pipe-delimited string. Then, I want to do this for the remaining
    > > cells (B3 to B146) in a successive list. Any advice on accomplishing this is
    > > GREATLY appreciated. Thanks in advance!
    > >
    > > Jeff Bloomer
    > > Business/Reporting Analyst
    > > Standard Register
    > > www.standardregister.com


  4. #4
    jbtenor1
    Guest

    RE: Comparison - Strings and Arrays

    I'm getting an error when I run it right now. Here's the exact function I
    entered:

    Function findStrings(ByVal srchstr As String)
    Set comprng = Range("ab2:ab54") <-- not a mistake, I had to change my
    range by a column
    findstr = ""
    For i = 1 To 53
    n = InStr(1, srchstr, comprng(i), vbTextCompare)
    If n < 0 Then
    findstr = findstr & Mid(srchstr, n, Len(comprng(i))) & "|"
    Next i
    If findstr < "" Then
    findStrings = Left(findstr, Len(findstr) - 1)
    Else
    findStrings = ""
    End If
    End Function

    The error I get is "Compile Error: Next without For". Is that because the
    "For" statement is outside the "If" statement? I'm a little rusty on my VB
    syntax, but I'm thinking that's what's causing the problem. Please advise,
    and I really appreciate the help!

    "Toppers" wrote:

    > Sorry
    >
    > For i = 2 To 10
    >
    > should be
    >
    > For i = 1 To 9
    >
    >
    >
    > "Toppers" wrote:
    >
    > > Try this UDF
    > >
    > > in C2 put =findstrings(B2) and copy down
    > >
    > > Function findStrings(ByVal srchstr As String)
    > > Set comprng = Range("aa2:aa10")
    > > findstr = ""
    > > For i = 2 To 10
    > > n = InStr(1, srchstr, comprng(i), vbTextCompare)
    > > If n <> 0 Then findstr = findstr & Mid(srchstr, n, Len(comprng(i))) & "|"
    > > Next i
    > > If findstr <> "" Then
    > > findStrings = Left(findstr, Len(findstr) - 1)
    > > Else
    > > findStrings = ""
    > > End If
    > > End Function
    > >
    > >
    > > "jbtenor1" wrote:
    > >
    > > > I'm posting this again in the hopes that someone has an answer. I am not
    > > > having any luck with the 'Find' or 'Search' functions.
    > > >
    > > > I am wanting to take a delimited string in a cell (B2) containing multiple
    > > > data elements and compare it to an array ($AA$2:$AA$10), then have the
    > > > matching data from the cell trimmed and displayed in a neighboring cell (C2).
    > > > I believe the best result would be for it to return the value(s) that match
    > > > one or more of the data elements in $AA$2:$AA$10.
    > > >
    > > > From the example below, if I could have B2 contain the string, C2 would
    > > > contain the function that gives me the result of the match. For instance,
    > > > $AA$2:$AA$10 contains:
    > > >
    > > > ACLEMON
    > > > BDUFOUR
    > > > BLANGLI
    > > > DDILUCE
    > > > DWELLS
    > > > ESCOTT
    > > > KRENKER
    > > > THUMENI
    > > > WROCHES
    > > >
    > > > If B2 contains:
    > > >
    > > > MROMANO|MTELLIG|JGURECK|MWOLK|LGAZDA|GVANBUH|CSHOAF|STILLER|RVERBIC|DSTEPHE|BLANGLI
    > > >
    > > > C2 should return a result of BLANGLI. If there is more than one piece of
    > > > matching data, then it would be great if C2 could display the multiple items
    > > > in a new pipe-delimited string. Then, I want to do this for the remaining
    > > > cells (B3 to B146) in a successive list. Any advice on accomplishing this is
    > > > GREATLY appreciated. Thanks in advance!
    > > >
    > > > Jeff Bloomer
    > > > Business/Reporting Analyst
    > > > Standard Register
    > > > www.standardregister.com


+ 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