我使用以下内容来删除列DX中的名称不是指定名称的所有数据行。代码将对所有行进行排序,并删除不包含该特定名称的每一行。问题是,这太慢了。 有什么想法吗?
Sub DeleteNonName()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "DX")
If Not IsError(.Value) Then
If InStr(.Value, "Name") = 0 Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
答案 0 :(得分:0)
Sub DeleteName() 使用ActiveSheet .AutoFilterMode = False 使用范围(" DX1",范围(" DX"& Rows.Count).End(xlUp)) .AutoFilter 1," 名称" On Error Resume Next .Offset(1).SpecialCells(12).EntireRow.Delete 结束 .AutoFilterMode = False 结束 Selection.AutoFilter 结束子