Home » excel » excel – Create matrix from multiple values in a single cell

excel – Create matrix from multiple values in a single cell

Posted by: admin May 14, 2020 Leave a comment


I have data like this in Excel:

SO18318488 question example

that I want to convert to a (5*7) matrix like this:

            sara   jone   shery  jack   joe    peter  beti
    book1   1      0      0      0      0      0      0
    book2   1      0      0      1      0      0      1
    book3   0      0      0      0      0      1      0
    book4   0      1      1      1      0      0      0
    book5   0      0      1      0      1      0      0

What can I do?

How to&Answers:

My choice would be to rearrange the data to suit a PivotTable. So copy ColumnC and Paste Special Values into ColumnD. Then replace blanks in ColumnD with nothing (to remove the space from book1, book2). Select ColumnD, Data > Data Tools – Text to Columns, Delimited, Comma then filter ColumnE to select non blank rows and copy the visible part of ColumnB (excluding header) to B9 (or to suit) and the visible part of ColumnE (excluding header) to D9 (or to suit). Then create your PivotTable from B1:D11 (or to suit) as shown (using ColumnD for belong – ie belong2):

SO18318488 example


Starting in cell A2, paste your list of books to create the left side of your grid.
Copy your list of IDs, then starting In cell B2, paste your list of ids by selecting paste special, transpose. This will create the top and side of your matrix.

Paste this formula in Cell B2


(WHERE $K:$L is a listing of ids, belong. i.e. The second and third columns in your sample data. These can be anywhere as long as you update the reference $K:$L to refer to the new location)

Now, copy Cell B2, and paste for the rest of the matrix.


Just in case on book’s title could be found within another book’s title (for example “The Ring” and “Fellowship of the Ring”), you could use this formula in cell F2 and copy over and down to cell L6:

=--ISNUMBER(SEARCH(","&$E2&",",","&SUBSTITUTE(VLOOKUP(F$1,$B$2:$C$8,2,FALSE),", ",",")&","))

Where F1:L1 is the list of the names and E2:E6 is the list of book titles