Excel 暂停VBA循环,直到重新计算图纸
我搜索谷歌直到第10页,但找不到解决这个问题的方法。 我在VBA中有一个循环,但希望它在继续之前等待,直到工作表重新计算 大多数人建议使用Excel 暂停VBA循环,直到重新计算图纸,excel,vba,loops,refresh,Excel,Vba,Loops,Refresh,我搜索谷歌直到第10页,但找不到解决这个问题的方法。 我在VBA中有一个循环,但希望它在继续之前等待,直到工作表重新计算 大多数人建议使用DoEvents。然而,这对我来说并不适用 这是我到目前为止的代码,它不会等待工作表计算完成: Sub Replaceifrebalance() Dim x As Integer NumRows = Range("CF16", Range("CF16").End(xlDown)).Rows.Count Range("CF16").Select F
DoEvents
。然而,这对我来说并不适用
这是我到目前为止的代码,它不会等待工作表计算完成:
Sub Replaceifrebalance()
Dim x As Integer
NumRows = Range("CF16", Range("CF16").End(xlDown)).Rows.Count
Range("CF16").Select
For x = 1 To NumRows
If Range("CF" & x).Value > 0 Then
Range("AW15:BF15").Select
Application.CutCopyMode = False
Selection.Copy
Range("AW1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("AW" & 1 & ":BF" & 1).Copy Worksheets("Timeseries").Range("BI" & x & ":BR" & x)
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
End If
End If
Next
End Sub
有人知道与此不同的解决方案吗
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
End If
如果无效,则在时使用
Do。对于If
,代码将计算一次,然后向前移动Do-While
将使其保持循环,直到满足条件
Do
DoEvents
Loop While Not Application.CalculationState = xlDone