CONCATENATE and TEXTJOIN formulas / Excel / VBA

1.5k views Asked by At

I'm having again some problems. Here's the deal:

enter image description here

I'd like to use the TEXTJOIN function to concatenate all the elements within the range A:G, skiping the potential empty cells. The problem is, I have to follow a certain order... This is what the H column indicates : a key where each letter represents a colum

My idea was to use this formula :

=CONCATENER("=";"JOINDRE.TEXTE("" - "";VRAI;";STXT(H2;1;1);LIGNE(H2);";";STXT(H2;2;1);LIGNE(H2);";";STXT(H2;3;1);LIGNE(H2);";";STXT(H2;4;1);LIGNE(H2);";";STXT(H2;5;1);LIGNE(H2);";";STXT(H2;6;1);LIGNE(H2);";";STXT(H2;7;1);LIGNE(H2);")")

(I know, it looks so bad haha)

And then copy and paste it in values in another cell to do the trick (= the actual resultat of the textjoin formula). Unfortunately that idea doesn't work...

I also tried to use the formula without the brackets around my separator in the textjoin formula and then replace " - " by "" - "" with a macro but it does not seem to work as well...

Any clue?

Thanks guys, and thanks to the ppl who already helped me in this post: VBA - Count empty cols, search and replace

Jean

2

There are 2 answers

0
Mister 832 On BEST ANSWER

This is the Textjoin function you're looking for:

 =TEXTJOIN("-",TRUE,INDIRECT(MID(H2,1,1)&ROW(H2)),INDIRECT(MID(H2,2,1)&ROW(H2)),INDIRECT(MID(H2,3,1)&ROW(H2)),INDIRECT(MID(H2,4,1)&ROW(H2)),INDIRECT(MID(H2,5,1)&ROW(H2)),INDIRECT(MID(H2,6,1)&ROW(H2)),INDIRECT(MID(H2,7,1)&ROW(H2)))
0
Vitor Barreto On

Alongside Mister 832 great answer, here is a (possible) alternative solution for those who don't have Excel 2016 Textjoin function.

=SUBSTITUTE(INDIRECT(MID(H2;1;1)&ROW(H2))&" "&INDIRECT(MID(H2;2;1)&ROW(H2))&" "&INDIRECT(MID(H2;3;1)&ROW(H2))&" "&INDIRECT(MID(H2;4;1)&ROW(H2))&" "&INDIRECT(MID(H2;5;1)&ROW(H2))&" "&INDIRECT(MID(H2;6;1)&ROW(H2))&" "&INDIRECT(MID(H2;7;1)&ROW(H2));"  ";" ")