VBA范围选择错误(删除一行)

时间:2014-07-21 16:01:00

标签: excel-vba vba excel

我希望实现一个VBA例程,该例程会自动删除第I列和第J列中的任何内容,其中包含' delete'因为这是我设置的验证返回。我有以下代码,但我的代码在第二个循环中断,我得到一个超出范围的下标。 Haven已经能够修复它,所以如果有人可以给出建议,我将非常感激。

Sub RemoveNA()
'THIS DELETES ALL ROWS WHERE THE VALUE IN COLUMN I IS "DELETE"
    Dim FoundCell As Range
    Application.ScreenUpdating = False
    Set FoundCell = Range("I:I").Find(what:="DELETE", LookIn:=xlValues)
    Do Until FoundCell Is Nothing
        FoundCell.EntireRow.Delete
        Set FoundCell = Range("I:I").FindNext
    Loop

    'THIS DELETES ALL ROWS WHERE THE VALUE IN COLUMN J IS "DELETE"
    Application.ScreenUpdating = False
    Set FoundCell = Range("J:J").Find(what:="DELETE", LookIn:=xlValue)
    Do Until FoundCell Is Nothing
        FoundCell.EntireRow.Delete
        Set FoundCell = Range("J:J").FindNext
    Loop

End Sub

1 个答案:

答案 0 :(得分:1)

看起来你错过了''在' LookIn:= xlValue'在第二个循环中。