How to autogenerate certain excel strings from certain inputs as given in example?

孤者浪人 提交于 2019-12-02 13:43:51

This can be down but I needed to use a small helper table to keep the counts of the number of size items in each row, the number of colours in each row, and finally a running total of the possible combinations for each row.

Proof of Concept

Caveats

Yes, there is more than one!

  • Sizes must remain consistant in number of characters. 7,8,9 or 10,11,12 is ok but 8,9,10 will not work. Work around is to use leading 0s.
  • Colours needs to be one continuous separated by a space. Comas will be removed. Red, Bright-Red Infra_Red are ok, but Blood Red is not.
  • You will need to adjust your ranges to suit your data.

Based on the data in the proof of concept image above, use these formulas in row 3 and copy down.

Column F:

=(LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1)

Column G:

=(LEN(C2)-LEN(SUBSTITUTE(C2,",",""))+1)

The above two formulas count the number of comas. Based on that number they determine the number of items in show for the row, and the number of different colours for the row.

Column H:

=F3*G3+H2

This keeps a running total of the number of combinations for each row.

Column J:

=INDEX($A$2:$A$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))&"-"&K3&"-"&L3

This pulls the name from the list in A2:A4 advancing the row as the formula is dragged down based on the running total of combinations. It then concatenates the string with "-" and text from adjacent columns.

Column K:

=MID(INDEX($B$2:$B$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1)),MOD((ROW(A2)-ROW($A$2)-IFERROR(INDEX($H$3:$H$5,MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)),0)),INDEX($F$3:$F$5,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1)))*FIND(",",INDEX($B$2:$B$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1)))+1,FIND(",",INDEX($B$2:$B$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1)))-1)

Where to begin with that bad boy above...Lets just say I broke it out into sever columns first and then back substitute those formulas as required until I got this. It basically pulls out the size letters in sequence and then starts again at the next colour. May have been simpler to make it dependent on the colour name change in the adjacent column. This formula is independent. of the colour name column.

Column L:

=SUBSTITUTE(TRIM(MID(SUBSTITUTE(INDEX($C$2:$C$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))," ",REPT(" ",LEN(INDEX($C$2:$C$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))))),((QUOTIENT(ROWS($A$2:A2)-1-IFERROR(INDEX($H$3:$H$5,MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)),0),(INDEX($H$3:$H$5,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))-IFERROR(INDEX($H$3:$H$5,MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)),0))/INDEX($G$3:$G$5,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))))*LEN(INDEX($C$2:$C$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))))+1,LEN(INDEX($C$2:$C$4,IFERROR(MATCH(ROW(A2)-ROW($A$2),$H$3:$H$5,1)+1,1))))),",","")

Similar to the previous formula this was developed over several columns and then brought back into one cell. It blows apart the colour names, and then grabs each name in sequence after the number of rows equal to the number of sizes has past.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!