简体   繁体   中英

Display all matching values in one comma separated cell

I have two columns of data in an Excel 2010 spreadsheet. In Column A is a category, and in Column B is a value. There will be multiple values in Column B for each unique category in Column A.

What I want to achieve in a separate sheet is to display all of the values for each each unique category in one comma (or semi-colon etc) separated cell.

For example, if my first sheet looks like this:

----------------------
| Category | Value   |
----------------------
| Cat1     | Val A   |
| Cat1     | Val B   |
| Cat1     | Val C   |
| Cat2     | Val D   |
| Cat3     | Val E   |
| Cat3     | Val F   |
| Cat3     | Val G   |
| Cat3     | Val H   |
----------------------

I'd want to display the following in another sheet:

---------------------------------------
| Category | Value                    |
---------------------------------------
| Cat1     | Val A,Val B,Val C        |
| Cat2     | Val D                    |
| Cat3     | Val E,Val F,Val G, Val H |
---------------------------------------

Can this be achieved with a formula? Vlookup will only find the first matching value, of course. I've Googled it, but the individual search terms involved in the query are so generic I'm getting swamped with inappropriate results.

Please try (in a copy on another sheet):

Insert a column on the left with =IF(B2<>B3,"","x") in A2 (assuming Category is in B1). In D2 put =IF(B1=B2,D1&", "&C2,C2) and copy both formulae down to suit. Copy and Paste Special Values over the top. Filter on ColumnA for x and delete selected rows. Unfilter and delete ColumnA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM