【问题标题】:How do I delete the last line of a multi-line cell如何删除多行单元格的最后一行
【发布时间】:2019-05-03 19:20:31
【问题描述】:

我有一个包含大约 4000 行多行单元格的 Excel 文件,我需要删除每个单元格的最后一行。

所有单元格的格式如下 - 每个单元格的最后一行也以相同的单词 (CODE:) 开头,但长度可能不同:

this is the first line
this is the second line
this is the third line
CODE: 123456789

收件人:

this is the first line
this is the second line
this is the third line

我也试过用“|”替换换行符符号并使用删除最后一个“|”之后的所有内容的公式但没有成功,几乎我发现的每个公式都在 Excel 中返​​回错误。

this is the first line|this is the second line|this is the third line|CODE:123456789

收件人:

this is the first line|this is the second line|this is the third line

多行或带符号无关紧要 - 任何一种方式都适合我。

【问题讨论】:

  • 什么是多行单元格?合并单元格?
  • 一个包含换行符(alt+enter)的单元格,我的错。
  • 标记为重复,使用链接中的代码找到最后一个“|”的位置然后使用 mid 选择该字符之前的所有内容
  • 什么版本的 Excel?

标签: excel


【解决方案1】:

在新单元格中输入:

=REPLACE(A1,FIND(CHAR(1),SUBSTITUTE(A1,CHAR(10),CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),"")))),LEN(A1),"")

该公式将最后一个 lf 字符替换为一个很少使用的字符 CHAR(1),然后从该字符到末尾的所有内容都替换为空字符串。

确保在新单元格上启用wrap text

如果你想在同一个单元格中替换它,你将需要 VBA

【讨论】:

    【解决方案2】:

    如果您的文字在 A1 中,请尝试:

    =LEFT(A1;FIND("CODE: ";A1)-1)
    

    更新:如果你用-2而不是-1,你也会去掉最后一个换行符(实际上图像是-2而不是-1

    【讨论】:

    • 非常有效:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 2011-05-12
    相关资源
    最近更新 更多