Excel宏 - 非常慢

时间:2016-05-03 10:09:27

标签: excel vba excel-vba

我想制作一个宏来检查A列中的日期是否比今天少。 如果是这样,宏应插入"完成"在G栏中。

Sub DoneCheck()

Dim rngZelle As Range, strText As String
With ActiveSheet

For Each c In Sheets("3. Umlagerungen").Range("A:A")
If c.Value < Int(Now) And Not (IsEmpty(c.Value)) Then c.Offset(0, 6).Value = "done"

Next c
End Sub

我知道它的编码很差但是有效...... 我寻求帮助的原因是因为它运行得很慢......

我尝试使用Application.ScreenUpdating但它没有改变任何东西。

提前谢谢你&amp;问候

1 个答案:

答案 0 :(得分:3)

您应该只检查A列中使用过的单元格,添加Application.ScreenUpdating = False总是有助于加快速度:

Sub DoneCheck()
Dim eRow as long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

eRow = Thisworkbook.Sheets("3. Umlagerungen").Cells(Rows.Count,1).End(xlUp).Row

For Each c In Thisworkbook.Sheets("3. Umlagerungen").Range("A2:A" & eRow)
    If c.Value < Int(Now) And Not (IsEmpty(c.Value)) Then c.Offset(0, 6).Value = "done"
Next c

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub