Excel VBA: How to remove substrings from a cell?

前端 未结 4 896
离开以前
离开以前 2021-01-06 08:01

I have a cell value like this:

This is a <\"string\">string, It should be <\"changed\">changed to <\"a\"> a number.

There

4条回答
  •  天涯浪人
    2021-01-06 08:47

    Assuming the text in cell A1, then try this code

    Sub DelDoubleString()
    Dim Text As String, Text2Replace As String, NewText As String
    On Error Resume Next        'Optional, in case there's no double string to be deleted
    Text = Cells(1, 1)
    
    Do
        Text2Replace = Mid$(Text, InStr(Text, "<"), InStr(Text, ">") - InStr(Text, "<") + 1)
        NewText = Application.WorksheetFunction.Substitute(Text, Text2Replace, vbNullString)
        Text = NewText
    Loop Until InStr(NewText, "<") = 0
    
    Cells(1, 1) = NewText
    
    End Sub
    

提交回复
热议问题