+ Reply to Thread
Results 1 to 9 of 9

need help reading out multiple cells of column as a string in a single cell

  1. #1
    Registered User
    Join Date
    10-15-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question need help reading out multiple cells of column as a string in a single cell

    Hello everyone (and sorry for that poor description in my threadtitle)

    I recently re-started working with Excel 2007 after many years of not using that software and am stuck with something already. I want to analyse genetic relationships among animals and have a table that goes like this:

    column A: name of individuals, e.g.
    A1: "animal1"
    A2: "animal2"
    A3: "animal3"
    (...)
    A100: "animal100"

    column B: name of father of individual in A, e.g.
    B1: "fatherA"
    B2: "fatherA"
    B3: "fatherB"
    (...)
    B100: "fatherQ"

    Now, here comes my problem, as in the next column C I want to list out all individuals that were fathered by the very father in B as a string, for example, like this
    C1: "animal1, animal2, (plus all others in column A with "fatherA")"
    C2: "animal1, animal2, (plus all others in column A with "fatherA")"
    C3: "animal3, (plus all others in column A with "fatherB")"
    and so on...

    I have spent the whole day trying to figure out what to put in cell C1 to produce the desired outcome, but without big success. Therefore, if anyone has a suggestion, I would greatly appreciate your help.

    Thanks for your attention,
    N
    Last edited by Narayan~; 10-16-2009 at 01:57 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: need help reading out multiple cells of column as a string in a single cell

    Use a User-Defined Function...

    Have a read through this thread...

    http://www.excelforum.com/excel-prog...ry-system.html
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    String concatenation

    You can't accomplish this with builtin Excel functions. You have to add a new string concatenation function to your sheet.

    My favorite UDF (User Defined Function) that accepts a "match parameter" is ConcatIF(), and I like it because it functions like a SUMIF() with two extra parameters, so I understand it.

    Here's the code:
    Please Login or Register  to view this content.
    How to install the User Defined Function:
    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The function is installed and ready to use.
    ==========

    It's used just like a SUMIF() formula, but it has two extra parameters.
    Let's put:
    Animals in Column A
    Fathers in Column B
    A father to "match" in D1
    Our list in E1...enter this formula in E1:

    =ConCatIf(B1:B100,D1,A1:A100,", ",TRUE)

    First parameter: Range to evaluate
    Second param: comparison string
    Third param: Range to return values from
    Fourth param: The delimiting string for the concatenation, I'm using a comma/space in this example
    Fifth param: (optional) TRUE means eliminate duplicated values, FALSE (or omitted) means string all values
    Last edited by JBeaucaire; 10-16-2009 at 03:36 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    10-15-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: need help reading out multiple cells of column as a string in a single cell

    Oh, thank you both so much for your quick response. What a great forum!

    I will try what you suggested and read the link and let you know if I succeeded.

    N

  5. #5
    Registered User
    Join Date
    10-15-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Smile Re: need help reading out multiple cells of column as a string in a single cell

    Stopping by to let you know it worked perfectly, JBeaucaire. Thanks again!

    best regards,
    N

  6. #6
    Registered User
    Join Date
    10-15-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Red face Re: need help AGAIN reading out multiple cells of column as a string in a single cell

    Good Sunday Evening everyone

    After I got so excellent and quick help solving my previous problem, I am hoping now that you may help me with a related, new difficulty:

    I have:
    column A: international individual identifier of animal (a number)
    column B: national individual identifier of animal (also a number)
    column C: international individual identifier of father of animal in A (number)
    column D: national individual identifier of father of animal in A (number)
    column E: desired output = all children of animal in A listed as a string

    In column E I want to use the code posted in response to my previous question with the formula given. It worked great to list all children of the respective animal in the current row.
    The problem now is that for some animals and for some fathers international identifiers are not available. I have alternative identifiers for those though. Therefore, I would like to introduce a second Variable as alternative search term (current cell in D), plus an alternative range to evaluate (column B) and an alternative range to get the results from (column B). Only if the respective international identifier is lacking and the cell in A or C is empty, I would like the program to use the alternative national identifiers instead (eg. if "xCriteria" is nothing then use "altxCriteria", if "compareRange" is nothing then use "altcompareRange", if "stringsRange" is nothing then use "altstringsRange").

    I have played around with the code a little, but I didn't figure it out yet. Particularly, I don't know where I should put the line that goes:

    If xCriteria is Nothing Then Set xCriteria = altxCriteria

    If anyone can teach me how to solve my problem, I would greatly appreciate.
    Thank you in advance,
    have a nice sunday,
    N

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: need help reading out multiple cells of column as a string in a single cell

    Please post a sample workbook demonstrating a fully representative set of data and then a sample of your desired results.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: need help reading out multiple cells of column as a string in a single cell

    Narayan~

    Please start a new thread with a new title...

  9. #9
    Registered User
    Join Date
    10-15-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: need help reading out multiple cells of column as a string in a single cell

    I just did that. Thanks.

+ 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