VBA代码导致excel滞后

时间:2017-03-16 14:16:07

标签: performance excel-vba lag vba excel

下面的代码用于根据输入的第一个日期减少日期,如果填充了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

1 个答案:

答案 0 :(得分:2)

可能这样,取决于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