Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用VBA根据更多标准删除Excel中的行?_Vba_Excel_Row - Fatal编程技术网

如何使用VBA根据更多标准删除Excel中的行?

如何使用VBA根据更多标准删除Excel中的行?,vba,excel,row,Vba,Excel,Row,当有2个或更多条件时,我需要删除一些包含特定数据的行 我有这样的代码: For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1 If Cells(i, "D") <> "xx" Or Cells(i, "D") <> "xxx" Then Cells(i, "A").EntireRow.Delete Next i 但在最后,它删除了除第一行之外的所有内容 尽管如此,当我只有一个条件时,

当有2个或更多条件时,我需要删除一些包含特定数据的行

我有这样的代码:

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    If Cells(i, "D") <> "xx" Or Cells(i, "D") <> "xxx" Then Cells(i, "A").EntireRow.Delete         
Next i
但在最后,它删除了除第一行之外的所有内容

尽管如此,当我只有一个条件时,代码工作得很好:

  For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
  If Cells(i, "D") <> "xx" Then Cells(i, "A").EntireRow.Delete
这将删除除行之外的所有内容,行在列D中包含“xx”


当我设置第二个条件和/或时,出现了什么问题以及为什么没有按我希望的方式工作?

您的和/或逻辑有一个小缺陷:


这里是您的更新代码,请尝试:

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    If Not (Lcase(Cells(i, "D")) = "xx" Or Lcase(Cells(i, "D")) = "xxx") Then Cells(i, "A").EntireRow.Delete         
Next i
由于XX=XX将返回false,但LCASEX=XX将返回true,因此已添加Lcase以删除区分大小写

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    If Not (Lcase(Cells(i, "D")) = "xx" Or Lcase(Cells(i, "D")) = "xxx") Then Cells(i, "A").EntireRow.Delete         
Next i