暂停VBA循环,直到重新计算表单

我search谷歌,直到第10页,但找不到解决scheme。 我在VBA中有一个循环,但是要在继续之前等待表格重新计算。 大多数人build议使用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 

有没有人现在有一个不同的解决scheme比这个?

  Application.Calculate If Not Application.CalculationState = xlDone Then DoEvents End If 

任何帮助是极大的赞赏。

使用的时候,如果没用的话。 IF代码将评估一次,然后向前移动。 尽pipe…将保持循环,直到条件满足。

 Do DoEvents Loop While Not Application.CalculationState = xlDone