Hi,
shantraj.antin@gmail.com!
If you want to give a try to a formula only solution give a look at the uploaded file.
It uses 2 helper columns in original data source (worksheet Sheet1, columns F:G as follows:
F1: "# Items"
G1: 0
F2: =(LARGO(D2)-LARGO(SUSTITUIR(D2;";#";"")))/2+1 -----> in english: =(LEN(D2)-LEN(SUBSTITUTE(D2,";#","")))/2+1
G2: =SUMA(F$2:F2)+0,001 -----> in english: =SUM(F$2:F2)+0.001
Copy down F2:G2 as required.
Check the 3rd worksheet, OutputFormulaOnly:
B2: =SI.ERROR(INDICE(Sheet1!$B$2:$E$7;COINCIDIR(FILA()-1;Sheet1!$G$1:$G$7;1);COLUMNA()-1);"") -----> in english: =IFERROR(INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1),"")
D2: =SI.ERROR(EXTRAE(SUSTITUIR(SUSTITUIR(";#"&INDICE(Sheet1!$B$2:$E$7;COINCIDIR(FILA()-1;Sheet1!$G$1:$G$7;1);COLUMNA()-1)&";#";";#";"@@";CONTAR.SI(E$2:E2;E2));";#";"&&";CONTAR.SI(E$2:E2;E2));HALLAR("@@";SUSTITUIR(SUSTITUIR(";#"&INDICE(Sheet1!$B$2:$E$7;COINCIDIR(FILA()-1;Sheet1!$G$1:$G$7;1);COLUMNA()-1)&";#";";#";"@@";CONTAR.SI(E$2:E2;E2));";#";"&&";CONTAR.SI(E$2:E2;E2)))+2;HALLAR("&&";SUSTITUIR(SUSTITUIR(";#"&INDICE(Sheet1!$B$2:$E$7;COINCIDIR(FILA()-1;Sheet1!$G$1:$G$7;1);COLUMNA()-1)&";#";";#";"@@";CONTAR.SI(E$2:E2;E2));";#";"&&";CONTAR.SI(E$2:E2;E2)))-HALLAR("@@";SUSTITUIR(SUSTITUIR(";#"&INDICE(Sheet1!$B$2:$E$7;COINCIDIR(FILA()-1;Sheet1!$G$1:$G$7;1);COLUMNA()-1)&";#";";#";"@@";CONTAR.SI(E$2:E2;E2));";#";"&&";CONTAR.SI(E$2:E2;E2)))-2);"") -----> in english: =IFERROR(MID(SUBSTITUTE(SUBSTITUTE(";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2)),SEARCH("@@",SUBSTITUTE(SUBSTITUTE(";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2)))+2,SEARCH("&&",SUBSTITUTE(SUBSTITUTE(";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2)))-SEARCH("@@",SUBSTITUTE(SUBSTITUTE(";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2)))-2),"")
Copy across B2 to D2:E2.
Copy down B2:E2 as required, i.e., until the first blank cell appears in column B and then delete that last one row formulas (in the example the rows with the copied formula are yellow shaded in column B).
The slightly long formula for column D works as follows:
a) It builds a string as:
";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#","
i.e.:
";#"&<Field_Column_in_source_Worksheet>&";#","
b) Replaces the ";#" nth+1 and nth+2 occurences with "@@" and "&&" respectively:
SUBSTITUTE(SUBSTITUTE(";#"&INDEX(Sheet1!$B$2:$E$7,MATCH(ROW()-1,Sheet1!$G$1:$G$7,1),COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2))
which is:
SUBSTITUTE(SUBSTITUTE(<string_of_a>,COLUMN()-1)&";#",";#","@@",COUNTIF(E$2:E2,E2)),";#","&&",COUNTIF(E$2:E2,E2))
c) Extracts the characters between "@@" and "&&" that is:
MID(<string_of_b>,SEARCH("@@",<string_of_b>)+2,SEARCH("&&",<string_of_b>)-SEARCH("@@",<string_of_b>-2)
d) Encloses the extracted substring into an error trap:
=IFERROR(<string_of_c>,"")
Hope it helps. Just advise if any issue.
Regards!