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

# excel – Create matrix from multiple values in a single cell

Questions:

I have data like this in Excel:

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?

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`):

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

``````=IF(ISERROR(FIND(\$A2,VLOOKUP(B\$1,\$K:\$L,2,FALSE))),0,1)
``````

(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.

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