my data set looks like
Col A
A/05702; A/05724; A/05724;A/05724;A/05725;A/05725;
corresponding Col B
1;1;2;3;1;3;
I am trying to get the results as
Col C
A/05702;A/5724;A05725
and corresponding
ColD1; 1,2,3; 1,3
This will look for same values in COLA, then if found COLB values goes to COLD and separated by ","
Any help is appreciated.
You don't NEED vba, you can do this with a pivot table:
You might need a UDF to concatenate the values easily, but that would be pretty simple too:
You can definitely leverage the
Dictionary
object from the Microsoft Scripting Runtime library. Add the the reference in your VBE with Tools->References.Basically, a dictionary allows you to store values against a unique key. You also want to create a set of unique keys but keep appending to the value for that key as you encounter new rows for that key.
Here's the code:
Update
For clarity, I will post screenshots of the data I entered to test this code. So, on my
Sheet2
- which was a totally new and empty of any other data - I've got these entries:And then after running the macro, it looks like this:
You can use this simple UDF:
Make sure to put it in a module attached to the desired workbook and NOT in the worksheet code or in ThisWorkbook code.
It is then called like this:
Entered as an Array formula with Ctrl-Shift-Enter. If done correctly Excel will put
{}
around the formula.NOTE
If you have Office 365 the UDF is not needed as it exists in Excel, Just enter the formula as an array.
Alternative
If you want a formula only approach AND your data is sorted then you will need a "helper column". I put mine in Column C. In C1 I put:
Which gave me:
Then a simple VLOOKUP will return what we want: