且构网

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

使用 Excel 公式将单元格拆分为多列

更新时间:2023-02-04 21:22:12

如果您想要一个等效于 Text to Columns 的公式并且 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.