Sub removeYourString()
Dim withParts As String
Dim removeParts As String
Dim withoutParts As String
withParts = Range("A1").Value
removeParts = Range("A2").Value & " "
withoutParts = Replace(withParts, removeParts, "")
Range("A3").Value = withoutParts
End Sub
删除所有列
Sub removeYourString()
Dim withParts As String
Dim removeParts As String
Dim withoutParts As String
Dim i As Integer
For i = 1 To 100
withParts = Range("A" & i).Value
removeParts = Range("B" & i).Value & " "
withoutParts = Replace(withParts, removeParts, "")
Range("C" & i).Value = withoutParts
Next i
End Sub
3 回答
阐述了SJR对
SUBSTITUTE
的建议:使用以下公式:
=TRIM(SUBSTITUTE(A1,B1,""))
. 把它放在C1中并复制列 . 这将从第1列中的字符串中删除第2列中的单词.TRIM
函数删除了删除单词的额外空格 . 如果一个单词可以作为另一个单词的子集出现(例如,单词是'test'但你的字符串是'Test, testing, 1, 2, 3'),你可以在过滤单词的末尾添加一个空格,以便'testing'不匹配 .如果单词出现多次,除非您指定要删除的匹配项,否则将删除所有匹配项 . 将
(A1,B1,"")
更改为(A1,B1,"",1)
将仅删除第一个匹配的匹配项 . 所以'Test1 test2 test3'将改为'1 test2 test3'试试这个:
删除所有列
或者使用公式并放入c1到c100
您可以在cell3中解决此公式: