2017-04-06 4 views
0

私は、y時間ステップで0からxまでカウントし、この値を1つのセルに配置するVBAスクリプトを持っています。オフセット式を使用することにより、このカウントを使用して別のシートからデータを読み取り、それを使用してxy散布図をアニメーション化することができます。期間によるカウンタ

使用されるコードは次のとおりです。

Sub Counter()      'Name and start of script 

For j = 0 To 200 Step 1   'Start of For loop setting j to equal a count from 0 to 2400 
    Range("A1").Value = j   'Place the value of j into cell A1 
    For c = 1 To 2500000   'Set a new variable called c and count from 0 to a value, this acts to slow down j's count else the animation would not be very long. Increasing this number will slow down the simulation and decreasing will speed it up 
    Next       'Move onto the next event 
    DoEvents      'Tells excel to do the For loop 
Next        'Move onto the next event 

End Sub 

アニメーショングラフを高速に実行できないようにするには、時間が無駄になります。これはコンピュータの速度に大きく依存します。 (古いコンピュータのほうが少ない)

私が達成したいのは、通常、データが0.1時間で0〜20秒にわたって生成されるため、期間が0からxまで数えられることです間隔。

したがって、アニメーションは、データが計算されるのと同じ時間だけ実行されます。モジュールの上部に

+0

「スリープ」の候補のように聞こえます – Winterknell

答えて

0

:次に

#If VBA7 Then 
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal milliseconds As LongPtr) 
#Else 
    Public Declare Sub Sleep Lib "kernel32" (ByVal milliseconds as Long) 
#End If 

:タイミングが右になるまで

Sub Counter() 
    For j = 0 To 200 
     Range("A1").Value = j 
     Sleep 100 ' or whatever - in milliseconds 
     DoEvents 
    Next 
End Sub 

は、ミリ秒を調整します。

+0

ありがとう、これが助けになりました! – Nemo51

関連する問題