+ Reply to Thread
Results 1 to 13 of 13

Help with Concatenate Data

Hybrid View

  1. #1
    Registered User
    Join Date
    05-28-2014
    Posts
    10

    Help with Concatenate Data

    Hello All

    I have a problem I hope you all can help me with.

    I have data in column's A & B. I am trying to combine data from Column B based on data in Column A to Column C. I was trying do something similar to SUMIF, to concatenate but it doesn't work.

    I am trying to achieve the following in Column C:

    Col. A Col. B Col. C
    1 dog dog, chicken
    2 cat cat, pig, rat
    1 chicken dog, chicken
    7 sheep sheep
    4 dog dog, chicken
    5 cow cow
    2 pig cat, pig, rat
    5 cow cow
    2 rat cat, pig, rat

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,897

    Re: Help with Concatenate Data

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Help with Concatenate Data

    A
    B
    C
    D
    1
    1
    dog dog, chicken C1 and down: {=CatIf($A$1:$A$9 = A1, $B$1:$B$9, ", ")}
    2
    2
    cat cat, pig, rat
    3
    1
    chicken dog, chicken
    4
    7
    sheep sheep
    5
    4
    dog dog
    6
    5
    cow cow, cow
    7
    2
    pig cat, pig, rat
    8
    5
    cow cow, cow
    9
    2
    rat cat, pig, rat


    Function CatIf(avbIf As Variant, _
                   rInp As Range, _
                   Optional sSep As String = ",", _
                   Optional bCatEmpty As Boolean = False) As String
      ' shg 2007
      ' UDF only
    
      ' Catenates the elements of rInp separated by sSep where the corresponding
      ' element of avbIf is True. Empty cells ignored unless bCatEmpty is True.
    
      Dim iRow          As Long
      Dim iCol          As Long
      Dim i             As Long
    
      On Error Resume Next
      i = UBound(avbIf, 2)
    
      If Err.Number Then
        ' avbIf is 1D
        For iRow = 1 To rInp.Rows.Count
          For iCol = 1 To rInp.Columns.Count
            i = i + 1
            If avbIf(i) Then
              If bCatEmpty Or Not IsEmpty(rInp(iRow, iCol).Value2) Then
                CatIf = CatIf & rInp(iRow, iCol).Value2 & sSep
              End If
            End If
          Next iCol
        Next iRow
      Else
        ' it's 2D
        For iRow = 1 To rInp.Rows.Count
          For iCol = 1 To rInp.Columns.Count
            If avbIf(iRow, iCol) Then
              If bCatEmpty Or Not IsEmpty(rInp(iRow, iCol).Value2) Then
                CatIf = CatIf & rInp(iRow, iCol).Value2 & sSep
              End If
            End If
          Next iCol
        Next iRow
      End If
    
      If Len(CatIf) Then CatIf = Left(CatIf, Len(CatIf) - Len(sSep))
    End Function
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    05-28-2014
    Posts
    10

    Re: Help with Concatenate Data

    Shg, thank you so much for your help!

    I added the function and input the formula then dragged it down, but it is displaying the same information for all the rows.

    For example:

    c1 is populating: dog, cat, chicken, sheep, dog, cow, pig, cow, rat

    I would like:
    c1: dog, chicken
    c2: cat, pig, rat
    c3: dog, chicken
    c4: sheep
    c5: dog, chicken

    Thanks again!
    Attached Files Attached Files

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

    Re: Help with Concatenate Data

    Don't understand why row 5 is "dog, chicken" since 4 is unique in col.A.
    Function ConcUniq(rng As Range, myItem) As String
        Dim e
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For Each e In Filter(rng.Parent.Evaluate("transpose(if(" & rng.Columns(1).Address & _
                                "=" & myItem & "," & rng.Columns(2).Address & "))"), False, 0)
                .Item(e) = Empty
            Next
            ConcUniq = Join(.keys, ", ")
        End With
    End Function
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-28-2014
    Posts
    10

    Re: Help with Concatenate Data

    Quote Originally Posted by jindon View Post
    Don't understand why row 5 is "dog, chicken" since 4 is unique in col.A.
    Hi Jindon,

    Row 5 is "dog, chicken" since row 5's b value "dog" was combined with another value. However that would not be the case if it were not, like row 4.

    Is there a way to get it to combine?

    Thanks!

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

    Re: Help with Concatenate Data

    Still not clear.

    What if multiple "dog" where col.A have many different/multiple numbers?

  8. #8
    Registered User
    Join Date
    05-28-2014
    Posts
    10

    Re: Help with Concatenate Data

    For example:

    there could be multiple. There would probably need to be a loop.

    Since "dog and chicken" were combined, any where either word is found would need to be combined.

    If row 4's B value was "chicken" instead of "sheep", C4 would need to be "dog, chicken".

    or if B8's value was "rat" instead of "cow" then C8 would need to be "cat, pig, rat, cow".

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

    Re: Help with Concatenate Data

    Sorry but logic is not clear so I will leave this to someone else.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Help with Concatenate Data

    My post shows the same results as your example.

    The formula MUST be confirmed with Ctrl+Shift+Enter instead of just Enter, entered in the first cell, and then copied down.
    Last edited by shg; 08-14-2016 at 03:33 PM.

  11. #11
    Registered User
    Join Date
    05-28-2014
    Posts
    10

    Re: Help with Concatenate Data

    thanks for responding

    The only issue is row number 5 in the table above.

    I somehow need the C5 value to be "dog, chicken", since dog was combined with chicken in another cell in column C (c1 & c3).

    Not sure if it possible to do.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Help with Concatenate Data

    I don't understand the logic, but expect it doesn't relate to dog and chickens.

  13. #13
    Registered User
    Join Date
    05-28-2014
    Posts
    10
    Quote Originally Posted by shg View Post
    I don't understand the logic, but expect it doesn't relate to dog and chickens.
    The animals in this example represent ppl conducting transactions.
    In some instances dog may conduct transactions for 1 (column A) and also 4, but chicken also conducted transactions for 1.

    So row 1 and 3 show dog, and chicken as conductors. But since dog also did transactions for 4 I need to combine this transaction with the others. I can sort by column c in the end and subtotal at each change in c. However with the current formula dogs transaction (4) will not be combined with the other transactions he conducted.

+ 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. Concatenate with Double Info in Concatenate Cell
    By MRoz in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-10-2015, 02:07 PM
  2. [SOLVED] Formula concatenate data in multiple rows based on match data in a different row.
    By kidkool in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2014, 11:01 AM
  3. Replies: 9
    Last Post: 12-13-2013, 07:40 PM
  4. Replies: 3
    Last Post: 09-20-2012, 04:26 PM
  5. [SOLVED] Concatenate only where there is data
    By tiger10012 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-05-2011, 03:55 PM
  6. Replies: 2
    Last Post: 04-12-2010, 12:35 PM
  7. [SOLVED] I know how to concatenate ,can one de-concatenate to split date?
    By QUICK BOOKS PROBLEM- in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-26-2005, 01:05 PM

Tags for this Thread

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