Excel: Group values from rows based on common cell value

大憨熊 提交于 2020-01-26 04:51:07

问题


I have an Excel file that contains a list of groups and the users that belong to them. I need to generate a list of users that belong to each group. Key point: while this is a trivial task in perl, python, or any other programming language, I'd like to do the whole thing in Excel so I don't have to export to csv, re-import the results, and re-do the formatting every time there's a change.

The file format (when exported to csv) is akin to:

Group, username, email
Perl Jam, evedder, evedder@pj.com
Perl Jam, mcameron, mcameron@soundgarden.com
Perl Jam, jament, jament@pj.com
Perl Jam, sgossard, sgossard@pj.com
Perl Jam, mmccready, mmccready@pj.com
Soundgarden, mcameron, mcameron@soundgarden.com
Soundgarden, ccornell, ccornell@soundgarden.com
Soundgarden, kthayill, kthayill@pj.com
Soundgarden, bshepherd, bshepherd@pj.com
Temple of the Dog, evedder, evedder@pj.com
Temple of the Dog, ccornell, ccornell@soundgarden.com
Temple of the Dog, jament, jament@pj.com
Temple of the Dog, sgossard, sgossard@pj.com
Temple of the Dog, mmccready, mmccready@pj.com
Temple of the Dog, mcameron, mcameron@soundgarden.com

What I'd like to end up with is:

Group, usernames
Perl Jam, evedder, mcameron, jament, sgossard, mmccready
Soundgarden, mcameron, ccornell, kthayill, bshepherd
Temple of the Dog, evedder, mcameron, ccornell, jament, sgossard, mmccready

回答1:


To get your unique list use this array formula:

=IFERROR(INDEX($A$2:$A$16,MATCH(0,COUNTIF($E$1:E1,$A$2:$A$16),0)),"")

Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

Put in first cell, hit Ctrl-Shift-Enter, then copy down till you get blanks.

To get the username:

=IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$16)/($A$2:$A$16=$E2),COLUMN(A:A))),"")

Where $E2 is the cell in which the other formula is.

Then copy across and down.



来源:https://stackoverflow.com/questions/43125972/excel-group-values-from-rows-based-on-common-cell-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!