+ Reply to Thread
Results 1 to 2 of 2

Concatenate Based on the Criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-04-2009
    Location
    ME
    MS-Off Ver
    Excel 2003,2007
    Posts
    157

    Concatenate Based on the Criteria

    Dear All,

    Appreciate your urgent support to build a concatenate formula. Attached the sample worksheet with desired result in last column.

    If Cell H2 matches with D:D range then merge corresponding Cell values in E:E in one cell.

    I was trying to put concatenate formula one by one cells, but its quite hectic to identify each range manually.

    Hope the attached spreadsheet will give better understanding for my desired result.


    Thanks a lot
    Attached Files Attached Files

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Concatenate Based on the Criteria

    I'd go with any one of the Concatenation UDF's floating on the web.

    However, you should note that the parameters repeat themselves in D:D which will concatenate quite a number of cells.

    Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, _
                        Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
                        
        Rem the first three argumens of ConcatIf mirror those of SUMIF
        Rem the Delimiter and NoDuplicates arguments are optional (default "" and False)
        Dim i As Long, j As Long
        
        With compareRange.Parent
            Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
        End With
        
        If compareRange Is Nothing Then Exit Function
        If stringsRange Is Nothing Then Set stringsRange = compareRange
        Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, _
                                                stringsRange.Column - compareRange.Column)
        
        For i = 1 To compareRange.Rows.Count
            For j = 1 To compareRange.Columns.Count
                If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
                    If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
                        ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
                    End If
                End If
            Next j
        Next i
        ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
    End Function
    Attached Files Attached Files
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

+ 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] Concatenate based upon criteria
    By ed_han in forum Excel General
    Replies: 8
    Last Post: 04-08-2015, 10:02 AM
  2. Concatenate cells based on criteria/threshold
    By amartin575 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-19-2015, 12:26 PM
  3. [SOLVED] Function to concatenate string based on a integer criteria
    By Tremper in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-19-2013, 10:03 AM
  4. Concatenate a range based on Criteria
    By nuruedriss in forum Excel General
    Replies: 1
    Last Post: 11-06-2013, 10:32 AM
  5. Pls help, can we concatenate text based on some criteria lik SUMIFS
    By Shermin in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-22-2013, 04:31 AM
  6. Concatenate Pivot Table fields based on criteria
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2012, 12:52 PM
  7. Concatenate multiple cells based on specific criteria
    By satkadeb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2011, 08:50 AM

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