Excel宏连续搜索3个项目,如果它们在那里则删除该行?

时间:2017-08-31 13:41:40

标签: excel vba excel-vba

我对此非常陌生,到目前为止我制作了几个宏,但与此相比它们很容易。我认为这需要实际的编程。

我需要在A栏中搜索一个词。然后,如果它在那里,我需要在列B中搜索格式。然后,如果这些是真的,我需要在C列中搜索一个术语。如果所有3都为真,我需要删除该行。有人可以帮忙吗?

到目前为止我有这个代码,这是我在宏下唯一拥有的东西。我以为我很接近但是没有用。

self.tableView.addSubview(self.refreshControl)

1 个答案:

答案 0 :(得分:1)

试试这个......

Dim indexRow As Long
Dim LastRow As Long

Dim keyA, keyE, keyI As String
Dim colA, colE, colI As Integer


keyA = "No Longer Employed"
keyE = "Bad"
keyI = "Hire Date"

colA = 1 ' index of col A
colE = 5 ' index of col E
colI = 9 ' index of col I


indexRow = 2 ' starting Row number from where start the loop 

'Find the last row in Column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row


For indexRow = indexRow To LastRow Step 1 ' this loop increments the indexRow  value

If ActiveSheet.Cells(indexRow, colA).Value = keyA Then
   If ActiveSheet.Cells(indexRow, colE).Value = keyE Then
    If ActiveSheet.Cells(indexRow, colI).Value = keyI Then

            ActiveSheet.Rows(indexRow).EntireRow.Delete
            indexRow = indexRow - 1 ' because we have just deleted one row

        End If
    End If
   End If

Next