Excelmacros – 非常慢

我想制作一个macros来检查列A中的date是否小于今天。 如果是这样,macros应该在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它,但它不会改变任何东西。

预先感谢您的问候

您应该只检查列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