如何从Excel的单元格中删除某些文本?

时间:2018-11-14 00:25:20

标签: excel

我在Excel中有一个包含以下内容的单元格:

@dickfundy @ThatKevinSmith @aliciamalone @MovieMantz @dickfundy不,只是陌生人第2季或Ready Player https:// xxxxxxxxxxx

我想删除用户名(所有以“ @”开头的内容),并且还希望删除网络链接(“ https:xxxxxxxxxxx”),最后在单元格中使用以下内容:< / p>

不要只是陌生人第二季或准备就绪玩家

我还有60,000个其他单元格包含相似的文本。我该怎么做?

3 个答案:

答案 0 :(得分:2)

我相信您的Excel版本具有TEXTJOIN功能。在这种情况下,您可以使用此 array-formula

=TEXTJOIN(" ",TRUE,IF((LEFT(TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999)))="@")+(LEFT(TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999)),4)="http"),"",TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",999)),seq_999,999))))

其中seq_999是一个命名公式,

refers to:  =IF(ROW(INDEX(Sheet1!$1:$65535,1,1):INDEX(Sheet1!$1:$65535,255,1))=1,1,(ROW(INDEX(Sheet1!$1:$65535,1,1):INDEX(Sheet1!$1:$65535,255,1))-1)*999)

要输入/确认数组公式,请在按下 enter 的同时按住 ctrl + shift 。如果正确执行此操作,Excel会在公式栏中显示的公式周围放置括号{...}

答案 1 :(得分:1)

如果您删除了最后一个用户名(用*@替换为空),则可以应用:

=LEFT(MID(A1,FIND(" ",A1),LEN(A1)),FIND("http",MID(A1,FIND(" ",A1)+1,LEN(A1))))

SO53291434 example

答案 2 :(得分:1)

作为UDF:

Function FixIt(s As String) As String
    s = CleanUp(s, "@")
    s = CleanUp(s, "http")
    FixIt = Trim(s)
End Function

'remove all text segments beginning with LookFor, up to the next space
'  or until the end of the input string s
Function CleanUp(s As String, LookFor As String) As String
    Dim pos As Long, pos2 As Long, rv As String
    rv = s
    pos = InStr(1, rv, LookFor)
    Do While pos > 0
        pos2 = InStr(pos + 1, rv, " ")
        If pos2 = 0 Then pos2 = Len(rv)
        rv = Left(rv, pos - 1) & Right(rv, Len(rv) - pos2)
        pos = InStr(1, rv, LookFor)
    Loop
    CleanUp = rv
End Function

如果您想要强大的东西:

How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops