Pivot table using comma separated cells

0

I need to mimic pivot tables for comma separated cells, and output into comma separated cells as well, grouping by country. I have about 100 rows of this data, so I cannot convert to column or rows.

The data

Col A | Col B

country1,country1,country3,country4,country4,country4,country8|number1,number2,number3,number4,number5,number6,number7

needed output

country1,country3,country4,country8|(number1+number2),number3,(number4+number5+number6),number7

I'm new to pivot tables, and any macro or VBA function is okay. Any ideas?

Hai Myster

Posted 2012-05-22T18:58:15.607

Reputation: 1

When you say comma separated cells, are the actually in different cells, or are then in the same cell> – soandos – 2012-05-22T19:00:29.963

the countries are in one cell, and the values are in another cell. – Hai Myster – 2012-05-22T19:12:01.627

Answers

0

The follow formula will work in excel 2007 and 2010 assuming the countries cell is A1 and that the values cell is B1 and that both cells contain 7 values separated by 6 commas:

Countries:

    =LEFT(A1,SEARCH(",",A1)-1)&","&LEFT(RIGHT(A1,LEN(A1)-SEARCH(",",A1,SEARCH(",",A1)+1)),SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1)+1)+1)-SEARCH(",",A1,SEARCH(",",A1)+1)-1)&","&LEFT(RIGHT(A1,LEN(A1)-SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1)+1)+1)),SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1)+1)+1)+1)-SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1)+1)+1)-1)&","&RIGHT(A1,LEN(A1)-SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1,SEARCH(",",A1)+1)+1)+1)+1)+1))

Values:

     =LEFT(B1,SEARCH(",",B1)-1)+LEFT(RIGHT(B1,LEN(B1)-SEARCH(",",B1)),SEARCH(",",B1,SEARCH(",",B1)+1)-SEARCH(",",B1)-1)&","&LEFT(RIGHT(B1,LEN(B1)-SEARCH(",",B1,SEARCH(",",B1)+1)),SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)-SEARCH(",",B1,SEARCH(",",B1)+1)-1)&","&LEFT(RIGHT(B1,LEN(B1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)),SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)-1)+LEFT(RIGHT(B1,LEN(B1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)),SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)+1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)-1)+LEFT(RIGHT(B1,LEN(B1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)+1)),SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)+1)+1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)+1)-1)&"," &RIGHT(B1,LEN(B1)-SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1,SEARCH(",",B1)+1)+1)+1)+1)+1))

This could also be done with VBA. Let me know if you're using an older version of excel and I can post that.

danielpiestrak

Posted 2012-05-22T18:58:15.607

Reputation: 411