使用“OR”逻辑运算符比较字符串

时间:2018-05-02 19:17:33

标签: excel excel-vba vba

For i = Last To 2 Step -1
    If Not (Cells(i, "A").Value) Like "*exe" Or (Cells(i, "A").Value) Like "*dll" Or (Cells(i, "A").Value) Like "*ocx" Then
        Cells(i, "A").EntireRow.Delete
    End If
Next i

大家好,我对VBA有点新意,想知道我是否能得到一些帮助。我在这里要做的是删除任何不以“exe”,“dll”或“ocx”结尾的行。按原样执行此操作,它将删除所有不以“exe”结尾的行。在这种情况下,我不确定我是否使用了正确的语法。我已经尝试过像往常一样搜索论坛但是这次我很难过...如果之前有人问过,我会感激任何帮助和道歉。谢谢!

1 个答案:

答案 0 :(得分:2)

认为你的括号有点混乱。你只需要在Not。之后包含整个子句。

For i = Last To 2 Step -1
    If Not (Cells(i, "A").Value Like "*exe" Or Cells(i, "A").Value Like "*dll" Or Cells(i, "A").Value Like "*ocx") Then
        Cells(i, "A").EntireRow.Delete
    End If
Next i
相关问题