试试这个(选择列表然后运行这个)
Sub Demo()
Dim cl As Range
For Each cl In Selection.Cells
If Trim(cl) Like "*[*]" Then
Cl = trim(cl)
cl = "to " & Left(cl, Len(cl) - 1)
End If
Next
End Sub
实际数据包括训练换行符,有时 * 前有一个空格,有时 * 后有术语
这个版本处理这些问题
Sub Demo()
Dim cl As Range
Dim r As Range
Dim str As String, i As Long
Set r = Selection
For Each cl In r.Cells
str = Trim(cl)
str = Replace(str, " *", "*")
If Asc(Right$(str, 1)) <= 31 Then
str = Trim(Left$(str, Len(str) - 1))
End If
If str Like "* be[*]*" Then
i = InStr(str, "*")
cl = "to be " & Left$(str, i - 4 & Mid$(str, i + 1))
ElseIf str Like "*[*]*" Then
i = InStr(str, "*")
cl = "to " & Left$(str, i - 1) & Mid$(str, i + 1)
End If
Next
End Sub