2016-05-04 8 views
-1

私は時間とともにデータを変更するチャートを作成しようとしています。 Yデータは同じですが、Xデータだけが変更されます。私はApplication.Waitを使って、X値の各変更の間にしばらく時間を許しています(私は私の目でそれを見ることができます)。しかし、私は非常に遅いコードを実行し、私は正しくApplication.Wait関数を使用しているかどうかはわかりませんが、私は0.5秒の各変更の間にしたい。それは、時間とともに変化するように私は、グラフを見ることができるように、それをよりスムーズにするそこの方法は時間を過ぎてデータが変化するグラフを作成しようとすると時間がかかりすぎるのですか?

がここ

(コード行をループとして)ですが、私のコードは次のとおりです。

Sub UpdateChart() 

Dim ChtObj As ChartObject 
Dim counter As Integer 
Dim timecount As Double 


Set ChtObj = ActiveSheet.ChartObjects.Add(200, 50, 500, 500) 

'Creating intial graph 
With ChtObj.Chart 
    'Chart Type 
    .ChartType = xlXYScatterSmooth 

    'Datainput 
    .SeriesCollection.NewSeries 
    .SeriesCollection(1).Name = "Bending moment" 
    .SeriesCollection(1).Values = Range("D3:H3") 
    .SeriesCollection(1).XValues = Application.Union(Cells(5, 4), Cells(5, 5), Cells(5, 6), Cells(5, 7), Cells(5, 8)) 
    .HasLegend = False 

    'Title 
    .HasTitle = True 
    .ChartTitle.Text = "Bending moment along pile " & ActiveSheet.Name & " at time 0 seconds" 

    'X-Axis 
    .Axes(xlCategory, xlPrimary).HasTitle = True 
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Bending moment (kN.m)" 
    'Y-Axis 
    .Axes(xlValue, xlPrimary).HasTitle = True 
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Length along pile (m)" 

End With 

'Loopingthrough data to be done** 
counter = 6 
timecount = 0 
While (Not IsEmpty(Cells(counter, 4))) 

    'Pausing for half a second and recording cumulative time 
    timecount = timecount + 0.5 
    Application.Wait (Now() + TimeValue("0:00:005")) 

    'Updating Chart data 
    With ChtObj.Chart 
     .SeriesCollection(1).XValues = Application.Union(Cells(counter, 4), Cells(counter, 5), Cells(counter, 6), Cells(counter, 7), Cells(counter, 8)) 
     .ChartTitle.Text = "Bending moment along pile " & ActiveSheet.Name & " at time " & timecount & " s" 
    End With 

    'Next row 
    counter = counter + 1 
Wend 
End Sub 
+0

私が思うに、[このSOポスト](http://stackoverflow.com/questions/18602979/how-to-give-a-time-delay-of-less-than-one-second -in-excel-vba)があなたの質問に答えます。 'Applicaton.Wait(Now()+ 1 /(24 * 60 * 60.0 * 2))'を試してください。 – OldUgly

答えて

0

これは解決するように見えました私の問題:

Public Function PauseEvent(ByVal Delay As Double) 
    Dim dblEndTime As Double 
    dblEndTime = Timer + Delay 
    Do While Timer < dblEndTime 
    DoEvents 
    Loop 
End Function