ConcatIF ??

Rikknor

New Member
Joined
May 26, 2006
Messages
7
Hello All

CountIf and SumIf are great and I use them quite a bit but today
I'm looking for a solution to a unique issue I'm having.

I have data in cells

ColumnA|ColumnB
---------- | ----------
Student1| TRA1
Student2| TRA1
Student1| TRA2
Student2| TRA2
Student3| TRA1
Student2| TRA3

I would like a formula, (although I could write this as a custom VBA function, a VBA function would entail moving modules from book to book. So a formula would be much nicer.) that would yield the following result...

ColumnD|ColumnE
---------- |-----------
Student1|TRA1,TRA2
Student2|TRA1,TRA2,TRA3
Student3|TRA1

Due to company policy (sigh) I cannot load third party add-ins, so this has to be with whatever Excel ships with.

Thank you
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
(although I could write this as a custom VBA function, a VBA function would entail moving modules from book to book. So a formula would be much nicer.)
Not sure if you knew this, but you can store VBA code in your Personal Workbook also. Then, it is available whenever Excel is open for any file (on that User's computer).

I do this with a lot of VBA code that I use in a lot of different places. Then it does not need to be stored in each individual workbook.
 
Upvote 0
Put the aconcat code in a standard module<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> aconcat(a<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Variant</SPAN>,<SPAN style="color:#00007F">Optional</SPAN> sep<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN> = "")<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN><SPAN style="color:#007F00">' Harlan Grove, Mar 2002</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> y<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Variant</SPAN>

    <SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">TypeOf</SPAN> a<SPAN style="color:#00007F">Is</SPAN> Range<SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> y<SPAN style="color:#00007F">In</SPAN> a.Cells
            aconcat = aconcat & y.Value & sep
        <SPAN style="color:#00007F">Next</SPAN> y
    <SPAN style="color:#00007F">ElseIf</SPAN> IsArray(a)<SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> y<SPAN style="color:#00007F">In</SPAN> a
            aconcat = aconcat & y & sep
        <SPAN style="color:#00007F">Next</SPAN> y
    <SPAN style="color:#00007F">Else</SPAN>
        aconcat = aconcat & a & sep
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>

    aconcat = Left(aconcat, Len(aconcat) - Len(sep))<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Function</SPAN></FONT>

Then
Book1
ABCD
1aaaoneaaa
2kkkxxxonetwothree
3aaatwo
4lllyyy
5aaathree
6
7
8
9
10
Sheet1


The above is an array formula, which requires entry via Control+Shift+Enter [CSE], not just Enter. Any direct edit of the formula will require re-entry via CSE. You can tell if the formula has been entered correctly, as it will have braces - { } - around it afterward.

EDIT Welcome to MrExcel
 
Upvote 0
Truly Amazing, Thank you so much for the solution and thank you for the warm welcome. I didn't know about storing VBA in my personal workbook, so thank you for that too. I suppose I could always paste values if I needed to send the book elsewhere.

I think I'm going to like it here.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top