且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Excel公式拆分几列的单元格

更新时间:2023-01-25 23:26:20

如果您想要一个等同于文本到列的公式,而A1包含文本要解析,然后在B1中输入:



= TRIM(MID(SUBSTITUTE($ A1,;,REPT(,999)),COLUMNS A:B)* 999-998,999))并复制。


I have a cell with the following content:

     A
1    text1;text2;text3;text4;text5

I'd like to divide it into five cells, one for each occurrence of ;, like this:

     B      C      D      E      F
1    text1  text2  text3  text4  text5

I know Excel has a "Text to columns" function, but I need this to be automated, so that's not an option. I've entered this in B1:

=left(A1;FIND(";";A1;1)-1)

This gets me text1, which is what I want. For the next cell I need text2. I've tried this:

=right(A1;len(A1)-len(B1)-1)

My sheet now looks like this:

     B      C
1    text1  text2;text3;text4;text5

My issue now is, that I need to remove everything after the first ;, but I can't seem to figure it out. Any ideas?

If you want a formula equivalent to Text to Columns and A1 contains the text to be parsed, then in B1 enter:

=TRIM(MID(SUBSTITUTE($A1,";",REPT(" ",999)),COLUMNS($A:B)*999-998,999)) and copy across.