|
Sub 清除()
Dim i%
For i = 5 To Cells(Rows.Count, 1).End(3).Row
If Cells(i, 11) = "—" Or Cells(i, 11) = 0 Then
Range("b" & i).Resize(1, 13).ClearContents
End If
Next i
End Sub
这个代码每次运行的时候都要好几秒钟,速度太慢。可有大侠帮我修改下吗? 我的工作表从(A5:N100)都有数据。
在某种情况下可以试下以下代码:
Sub 清除()
Dim ar(), s$, i%
Application.ScreenUpdating = 0
i = Cells(Rows.Count, 1).End(3).Row
ar = Cells(5, 11).Resize(i, 1).Value
For i = 1 To UBound(ar)
If ar(i, 1) = "—" Or ar(i, 1) = 0 Then
s = s & ",b" & i + 4 & ":n" & i + 4
If Len(s) > 200 Then
s = Mid(s, 2)
Range(s).ClearContents
s = ""
End If
End If
Next i
If Len(s) Then
s = Mid(s, 2)
Range(s).ClearContents
End If
End Sub
如果表中数据多而需要ClearContents的单元格很少,则可以试试find
etc.
|
|