这就是我理解你的问题的方式——单元格中的每个单词都应该有“+”,除了被排除的单词。
试试下面的代码。请参阅下面的一些评论
Sub Add_Plus()
Dim r As Range
Dim SkipWords As Variant
'put all excluded word here, separate, within quotation marks
SkipWords = Array("place", "all", "words", "to", "skip", "here")
Dim tmpWords As Variant
Dim i As Integer, j As Integer
Dim Final As String, boExclude As Boolean
For Each r In Selection
tmpWords = Split(r.Value, " ")
For i = 0 To UBound(tmpWords)
For j = 0 To UBound(SkipWords)
If UCase(SkipWords(j)) = UCase(tmpWords(i)) Then
'do nothing, skip
boExclude = True
Exit For
End If
Next j
If boExclude = False Then
Final = Final & "+" & tmpWords(i) & " "
Else
'this will keep excluded words without "+"
'remove it if you want to remove the excluded words
Final = Final & tmpWords(i) & " "
End If
boExclude = False
Next i
r = Left(Final, Len(Final) - 1)
Final = ""
Next
End Sub
运行代码后,以下单元格:
do re mi
fa sol la
do place all
to words skip
here do re
place all
将被替换为:
+do +re +mi
+fa +sol +la
+do place all
to words skip
here +do +re
place all