【发布时间】:2019-08-04 07:13:06
【问题描述】:
这是我的代码的一部分。有没有办法让它变得简单?谢谢。
For i = 2 To ws.Range("E1").CurrentRegion.Rows.Count
If ws.Cells(i, 4).Value Like ("*SSI*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Settlement instruction*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*delivery Instruction*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Request form*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.cells(i, 4).Value Like ("*Sales to onboarding*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Application*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Doc Check list*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime to Credit*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime to Legal*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime_Legal*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime_Credit*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*LEXIS*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Withdrawal Request*") Then ws.Cells(i, 4).EntireRow.Delete
Next i
【问题讨论】:
-
布尔条件 = 类似条件 1 或类似条件 2 或类似条件 3 ...等。如果(条件)EntireRow.Delete.
-
注意 - 你有这个的方式,也许这就是你需要的,但如果
Cells(2,4)有SSI,那么它将删除该行。然后它将再次查看Cells(2,4),检查其中是否有Settlement instruction,如果有,请删除,然后再次查看下一个...等. -
还有
VBA.Filter()函数。 see here
标签: excel vba wildcard vb-like-operator