删除范围失败的方法vba

时间:2015-08-12 15:05:29

标签: excel vba excel-vba

我有2列,我在A和B列的每个单元格上进行比较,行数为1613,以检查它是否包含选定数量的字符串。然后我尝试删除该行,如果它不包含任何字符串但是我遇到了错误Delete method of Range class failed但是我不确定是什么问题

Sub macro()
Dim i As Integer
Dim ws As Worksheet
Set xSheet = Worksheets("RAW DATA (2)")
xSheet.Select
For i = 1 To 1613
    If InStr(Cells(i, 2).Value, "Error") = False Or InStr(Cells(i, 2).Value, "No credentials") = False Or InStr(Cells(i, 2).Value, "Connection Failed") = False Then
        xSheet.Rows(i).Delete
    End If
Next i
End Sub

1 个答案:

答案 0 :(得分:0)

哦,你很亲密!只需在该行添加“EntireRow”限定符(我不知道这是否是正确的术语):List of instances: [<__main__.example object at 0x7fdc77082c50>, <__main__.example object at 0x7fdc77082be0>, <__main__.example object at 0x7fdc77082c88>, <__main__.example object at 0x7fdc77082b00>, <__main__.example object at 0x7fdc77082b38>] Objects to remove: [<__main__.example object at 0x7fdc77082c88>, <__main__.example object at 0x7fdc77082c50>, <__main__.example object at 0x7fdc77082b38>]