CONCATENATE and TEXTJOIN formulas / Excel / VBA

余生颓废 提交于 2019-12-08 04:41:21

问题


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

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


回答1:


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)))



回答2:


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));"  ";" ")


来源:https://stackoverflow.com/questions/41193302/concatenate-and-textjoin-formulas-excel-vba

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