VBA宏未运行

时间:2017-01-19 05:32:50

标签: excel vba excel-vba

我在VBA中创建了以下宏,但是当我调用它时没有任何反应。任何想法为什么这可能不起作用?

Sub RemoveWords(DeleteFromCol As Range, FindCol As Range)

  Dim words As New Collection
  Dim r As Range
  Dim word As Variant

  For Each r In FindCol
    words.Add (r.Value2)
  Next r

  For Each r In DeleteFromCol
    For Each word In words
      r.Value2 = Replace(r.Value2, word, "")
    Next word
  Next r

End Sub

Sub Remove()

RemoveWords Range("A1:A233"), Range("B1:B5")

End Sub

2 个答案:

答案 0 :(得分:0)

宏不起作用,因为您可能没有传递强制参数:

(DeleteFromCol As Range, FindCol As Range)

这是对的吗?

答案 1 :(得分:0)

现在就搞定了。这是因为其中包含多个单词的单元格。您必须将单元格拆分为每个包含1个单词,并且运行正常。