Solution
With the formula used, it is possible to find only continuous values in the string.
Then it is necessary to find the antepenultimate value and the last and then concatenate, but error may occur when the string has no spaces " "
Last
To find the last value, the following formula is used:
=ARRUMAR(ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));40);40))
Antepenultimate
To find the antepenultimate value, the following formula is used:
=ARRUMAR(ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));120);40))
Concatenation
Then they are concatenated with:
=ARRUMAR(CONCAT(ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));120);40);ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));40);40)))
Checking
Checks if there are more than two spaces in the cell with:
=SE((NÚM.CARACT(A2)-NÚM.CARACT(SUBSTITUIR(A2;" ";"")))>1;"Fórmula caso haja mais que dois espaços";"ERRO")
Formula
=SE((NÚM.CARACT(A1)-NÚM.CARACT(SUBSTITUIR(A1;" ";"")))>1;ARRUMAR(CONCAT(ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));120);40);ESQUERDA(DIREITA(SUBSTITUIR(""&ARRUMAR(A1);" ";REPT(" ";40));40);40)));"ERRO")
Newer Excel versions use the function CONCAT()
and the old CONCATENAR()
Please insert the formula currently used as code and not as image.
– danieltakeshi
=TIDY(LEFT(RIGHT(REPLACE(""&TIDY(A99);" ";REPT(" ";20));41);40))
– Elienay Junior