我将很多Raw数据导入到“数据”表中,还有另一张名为“ Roster”的表(不言自明)。我想删除“数据”中不包含“名称”中任何名称的所有行。数据中的信息是“花名册”中的J列和A列。我目前正在使用下面的代码,但是需要很长时间。
Sub roster_cleanup()
Const sh1Col As String = "J"
Const sh2Col As String = "A"
Dim ws1 As Worksheet, ws2 As Worksheet
Dim r1 As Long, r2 As Long
Set ws1 = Sheets("Data")
Set ws2 = Sheets("Roster")
r1 = ws1.Cells(Rows.Count, sh1Col).End(xlUp).Row
r2 = ws2.Cells(Rows.Count, sh2Col).End(xlUp).Row
For i = r1 To 2 Step -1
For Each r In ws2.Range(sh2Col & "2:" & sh2Col & r2)
If ws1.Cells(i, sh1Col).Value = r.Value Then GoTo myNext
Next r
ws1.Cells(i, sh1Col).EntireRow.Delete
myNext:
Next i
End Sub
答案 0 :(得分:0)
尝试添加:
Application.ScreenUpdating = False 'Turn off screen updating. Code runs faster without screen flicker
Application.Calculation = xlManual 'Turns auto calc to manual
在代码的开头和:
Application.Calculation = xlAutomatic 'turns auto calc back on
Application.ScreenUpdating = True 'Turn on screen updating
在代码末尾,恰好在End Sub之前。
过去,我通过将带有vlookup的“骗子列”添加到远程封闭引用列表中来解决此问题。然后,我将使用VBA在数据上放置一个自动筛选器,并使用.SpecialCells(xlCellTypeVisible).EntireRow.Delete
仅删除可见行...然后清除帮助程序查找列。非常快!希望这会有所帮助,并祝你好运。