如何从该列中查找特定文本并仅逐行删除多行中的该文本

时间:2018-07-08 17:36:05

标签: excel vba excel-vba

专家,我在宏观方面正面临问题。我有两张纸,一张叫做“沃尔玛”,它看起来像这样。

enter image description here

另一个工作表是“列表”

看起来像这样... enter image description here

现在,如果您注意到第二张纸中的列名带有“ Wal-Mart Banned Words”,则每个单元格中的单词均不同。我想要一个宏,它可以搜索写在禁止列表列中的单词,就像我在3号J单元格中写为Delux一样,它应该从所有行中产品列的其他搜索中搜索,并删除找到的地方。其余文本应相同,但单词“ Delux”将被删除。...

有可能......

我正在尝试这个录制的宏。...

enter image description here

1 个答案:

答案 0 :(得分:1)

Option Compare Text
Sub StackOverflow()


Dim banned_words() As String
Dim counter As Integer

Range("J2").Activate

counter = 0

Do While ActiveCell <> ""
    ReDim Preserve banned_words(counter + 1)
    banned_words(counter) = ActiveCell.Value
    ActiveCell.Offset(1, 0).Activate
    counter = counter + 1
Loop

Range("N2").Activate

Do While ActiveCell <> ""
    For Each bad_word In banned_words
        ActiveCell.Value = Replace(ActiveCell.Value, bad_word, "")
    Next bad_word
    ActiveCell.Offset(1, 0).Activate
Loop

End Sub