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


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"结尾的行。不确定在这种情况下我是否使用了正确的语法。我已经尝试像往常一样搜索论坛,但这次我被难住了......如果之前有人问过,将不胜感激任何帮助和道歉。谢谢!

认为你只是把括号弄混了。您只需要一个将整个子句括在 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

最新更新