Remove text appearing between two characters - multiple instances - Excel

后端 未结 3 1945
终归单人心
终归单人心 2021-01-22 13:21

In Microsoft Excel file, I have a text in rows that appears like this:

1. Rc8 {[%emt 0:00:05]} Rxc8 {[%emt 0:00:01]} 2. Rxc8 {[%emt 0:00:01]} Qxc8 {} 3. Qe7#  1-         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-22 14:08

    It is not that easy without VBA, but there is still a way.

    Either (as suggested by yu_ominae) just use a formula like this and auto-fill it:

    =IFERROR(SUBSTITUTE(A2,MID(LEFT(A2,FIND("}",A2)),FIND("{",A2),LEN(A2)),""),A2)
    

    Another way would be iterative calculations (go to options -> formulas -> check the "enable iterative calculations" button)
    To do it now in one cell, you need 1 helper-cell (for my example we will use C1) and the use a formula like this in B2 and auto-fill down:

    =IF($C$1,A2,IFERROR(SUBSTITUTE(B2,MID(LEFT(B2,FIND("}",B2)),FIND("{",B2),LEN(B2)),""),B2))
    

    Put "1" in C1 and all formulas in B:B will show the values of A:A. Now go to C1 and hit the del-key several times (you will see the "{}"-parts disappearing) till all looks like you want it.

    EDIT: To do it via VBA but without regex you can simply put this into a module:

    Public Function DELBRC(ByVal str As String) As String
      While InStr(str, "{") > 0 And InStr(str, "}") > InStr(str, "{")
        str = Left(str, InStr(str, "{") - 1) & Mid(str, InStr(str, "}") + 1)
      Wend
      DELBRC = Trim(str)
    End Function
    

    and then in the worksheet directly use:

    =DELBRC(A2)
    

    If you still have any questions, just ask ;)

提交回复
热议问题