【发布时间】:2017-10-18 13:02:25
【问题描述】:
在大约 50.000 行的文件中,我想删除 B 列中没有特定数字的行。我使用以下代码:
Sub DelRows()
Application.ScreenUpdating = False
Worksheets("2016").Activate
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, "B").Value <> "1060" And _
Cells(i, "B").Value <> "1061" And _
Cells(i, "B").Value <> "1062" And _
Cells(i, "B").Value <> "1063" And _
Cells(i, "B").Value <> "1064" And _
Cells(i, "B").Value <> "1105" And _
Cells(i, "B").Value <> "11050" And _
Cells(i, "B").Value <> "11051" And _
Cells(i, "B").Value <> "11053" And _
Cells(i, "B").Value <> "11054" And _
Cells(i, "B").Value <> "1160" And _
Cells(i, "B").Value <> "1161" And _
Cells(i, "B").Value <> "1162" And _
Cells(i, "B").Value <> "1163" And _
Cells(i, "B").Value <> "1164" And _
Cells(i, "B").Value <> "1166" And _
Cells(i, "B").Value <> "1168" And _
Cells(i, "B").Value <> "1169" And _
Cells(i, "B").Value <> "8060" And _
Cells(i, "B").Value <> "8061" And _
Cells(i, "B").Value <> "8062" And _
Cells(i, "B").Value <> "8063" And _
Cells(i, "B").Value <> "8064" And _
Cells(i, "B").Value <> "8068" And _
Cells(i, "B").Value <> "8192" Then
Cells(i, "B").EntireRow.Delete
End If
Next i
End Sub
这个宏需要很多时间,而且似乎有最多的'and-statements'。
我尝试使用数组或过滤器来解决这个问题,但对于初学者来说这很难。
我想将数字作为范围放在单独的工作表上,例如:
A
1 1060
2 1061
3 1062
4 1063
5 1064
…
我试图通过https://www.rondebruin.nl/win/winfiles/MoreDeleteCode.txt 上的 Criteria range on a different sheet* 部分来解决这个问题,但我并不完全理解这个 VBA 代码。
有人可以帮帮我吗? 亲切的问候, 理查德
【问题讨论】:
-
您是否尝试过实现该代码?你有多少列数据?