Performance 导致excel滞后的VBA代码

Performance 导致excel滞后的VBA代码,performance,excel,lag,vba,Performance,Excel,Lag,Vba,下面的“我的代码”用于根据输入的第一个日期递减日期,如果B列已填充。由于导入Excel的数据非常大,因此此计算现在导致我的Excel滞后。有没有办法加快速度 For i = 1 To rowNow - 3 newDate = DateAdd("d", -i, oldDate) For Each Cell In Range("A:A").Cells If IsEmpty(Cell) = True And IsEmpty(Range("B:B")) = False Then Cell.Valu

下面的“我的代码”用于根据输入的第一个日期递减日期,如果B列已填充。由于导入Excel的数据非常大,因此此计算现在导致我的Excel滞后。有没有办法加快速度

For i = 1 To rowNow - 3

newDate = DateAdd("d", -i, oldDate)

For Each Cell In Range("A:A").Cells

If IsEmpty(Cell) = True And IsEmpty(Range("B:B")) = False Then Cell.Value = newDate: Exit For

Next
Next

可能是这样,取决于B栏中的内容:

For i = 1 To rowNow - 3
    newDate = DateAdd("d", -i, oldDate)
    With Range("A:A")
        On Error Resume Next
        Intersect(.SpecialCells(xlCellTypeBlanks), .Offset(, 1).SpecialCells(xlCellTypeConstants).Offset(, -1))(1).Value = newDate
    End With
Next i

对于循环的每一次迭代,您都可能要检查一百万个单元格-真的有必要吗?@SJR抱歉,我对vba有点陌生。你的意思是每个函数的“For”都会导致这种情况吗?我确实尝试过改变这个,但是,如果我不使用这个函数,它不会减少日期。是的,你的内部循环-无论如何,请看下面两个建议的解决方案。