Search code examples
excelexcel-formulaworksheet-functionsubstitutionvba

Separate some values by brackets and decrease a number from a column to another column


I have an input with these values in different columns:

First column   Second Column    Third column
72              54,72            35,43
63              63,70,74         41
39              32,39,49         51

From this table I need an output like this:

First_output   Second_output      Third_output
50              54,35,43          [50,54][54][35,43]
50              70,74,41          [50,70,74][70,74][41]
50              32,49,51          [50,32,49][32,49][51]

First_output I made it with if(First column>100,First column,50),
second_output and third_output is a little headache for me, I've tried something with concatenate, but I couldn't get rid of First column for different scenarios.

RULES:

  • First_output will become 50 in place of 72,63,39
  • Second_output will become Second Column&Third column concatenated but without numbers that are in first column (which are 72,63,39)
  • Third_output will become, in brackets: first brackets contains second column, but as I said 72,63,39 will become 50 and that's why I have those numbers, second brackets contain same numbers without 50, third brackets contain third column.

Solution

  • Assuming First column is in A1, not VBA, in D2:

    50  
    

    in E2:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2&","&C2,A2,","),",,,",","),",,","")  
    

    in F2:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("[50,"&SUBSTITUTE(B2,A2,"")&"]["&SUBSTITUTE(B2,A2,"")&"]["&C2&"]",",,",","),",]","]"),"[,","[")  
    

    and copy all three down to suit.