VBAmacros,从列中删除关键字的行

我试图写一个VBA的macros,将通过其中一列(比如说D),并比较那里的名单与我将在第2页上的排除列表。然后是需要删除一个匹配的单词行并向上移动列表,直到整个列表清除与这些词的行。

在这里,据我所知,但由于某种原因,它什么也没有做。

Sub Delete_Exeptions() x = 2 Do While ThisWorkbook.Sheets("List1").Cells(x, 4) <> "" i = 11 Do While ThisWorkbook.Sheets("List2").Cells(i, 1) <> "" If ThisWorkbook.Sheets("List1").Cells(x, 4).Value = ThisWorkbook.Sheets("List2").Cells(i, 1).Value Then ThisWorkbook.Sheets("List1").Cells(x, 4).EntireRow.Delete i = i + 1 Loop x = x + 1 Loop 

这个人工作得很好,如果有人没有兴趣:

 Sub Delete_Exeptions() x = 2 Do While ThisWorkbook.Sheets("List1").Cells(x, 4) <> "" i = 11 Do While ThisWorkbook.Sheets("List2").Cells(i, 1) <> "" If ThisWorkbook.Sheets("List1").Cells(x, 4).Value <> ThisWorkbook.Sheets("List2").Cells(i, 1).Value Then Else: ThisWorkbook.Sheets("List1").Cells(x, 4).EntireRow.Delete End If i = i + 1 Loop x = x + 1 Loop End Sub 

那么这是最后的eddit,我已经改变为推荐,所以第一个循环从最后一行到第一,因为我遇到了问题,当我有两个排除在一排。 但是我决定不使用推荐的其他方法(Match和CurentRegion),因为它们并不真正为我工作。

 Sub Test_Bottom_toup() Dim str As String Dim strArr() As String Dim ws As Worksheet Dim lRow As Long Set ws = ThisWorkbook.Sheets("List1") With ws lRow = .Range("D" & .Rows.Count).End(xlUp).Row End With x = lRow Do While x <> 1 str = ThisWorkbook.Sheets("List1").Cells(x, 4) strArr = Split(str, " - ") ' This one is for my data spesifically as I had a random number before actual name, which might not be on the list of exlusions. i = 11 Do While ThisWorkbook.Sheets("List2").Cells(i, 1) <> "" If strArr(1) <> ThisWorkbook.Sheets("List2").Cells(i, 1) Then Else: ThisWorkbook.Sheets("List1").Cells(x, 4).EntireRow.Delete End If i = i + 1 Loop x = x - 1 Loop 

结束小组