Results 1 to 10 of 10

Thread: How search two values and concatenate the result from one column !!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    6
    Rep Power
    0

    How search two values and concatenate the result from one column ?

    I have tried to implement the VBA below (I found it in this forum) in the attached excel file, but does not work with two search criteria !!! Please, some help.

    Code:
    Function Multi_LookUpConcat(ByVal SearchList As String, SearchRange As Range, ReturnRange As Range, _
                          Optional SearchListDelimiter As String = ",", _
                          Optional Delimiter As String = " ", _
                          Optional MatchWhole As Boolean = True, _
                          Optional UniqueOnly As Boolean = False, _
                          Optional MatchCase As Boolean = False)
                      
      Dim X As Long, CellVal As String, ReturnVal As String, Result As String
      
    'Parse the SearchList into Strings
    ' Spaces next to the delimiters will be ignored
    Dim SearchString As String
    Dim List As String
    Dim C1 As Integer
    Dim C2 As Integer
    
      If StrComp(SearchList, "") = 0 Then
        Multi_LookUpConcat = ""
    
      ElseIf (SearchRange.Rows.Count > 1 And SearchRange.Columns.Count > 1) Or _
         (ReturnRange.Rows.Count > 1 And ReturnRange.Columns.Count > 1) Then
        Multi_LookUpConcat = CVErr(xlErrRef)
      
      Else
        
        SearchList = SearchList & SearchListDelimiter   'Ensure that it runs at least once
        C1 = 1
        C2 = InStr(C1, SearchList, SearchListDelimiter)
        
        While C2 > 0
            SearchString = Trim(Mid(SearchList, C1, C2 - C1))
    
            If Not MatchCase Then SearchString = UCase(SearchString)
            For X = 1 To SearchRange.Count
              If MatchCase Then
                CellVal = SearchRange(X).Value
              Else
                CellVal = UCase(SearchRange(X).Value)
              End If
              ReturnVal = ReturnRange(X).Value
              If MatchWhole And CellVal = SearchString Then
                If UniqueOnly And InStr(Result & Delimiter, Delimiter & ReturnVal & Delimiter) > 0 Then GoTo Continue
                Result = Result & Delimiter & ReturnVal
              ElseIf Not MatchWhole And CellVal Like "*" & SearchString & "*" Then
                If UniqueOnly And InStr(Result & Delimiter, Delimiter & ReturnVal & Delimiter) > 0 Then GoTo Continue
                Result = Result & Delimiter & ReturnVal
              End If
    Continue:
            Next
       
        ' Advance the pointers to search for the next element
        C1 = C2 + 1
        C2 = InStr(C1, SearchList, SearchListDelimiter)
        Wend
        
        Multi_LookUpConcat = Mid(Result, Len(Delimiter) + 1)
      
      End If
      
    End Function
    Attached Files Attached Files
    Last edited by pub; 12-21-2017 at 03:36 PM.

Similar Threads

  1. Replies: 30
    Last Post: 04-15-2019, 07:36 PM
  2. Upgrade to LookUpConcat UDF: Search Multiple Criteria and concatenate.
    By DJE in forum Excel and VBA Tips and Tricks
    Replies: 3
    Last Post: 05-23-2018, 12:18 AM
  3. Replies: 2
    Last Post: 07-23-2013, 06:54 PM
  4. Function to Concatenate Values
    By Admin in forum Download Center
    Replies: 1
    Last Post: 12-13-2012, 11:38 AM
  5. Concatenate multiple values
    By mcpizzle in forum Excel Help
    Replies: 3
    Last Post: 08-30-2012, 04:03 PM

Posting Permissions

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