散布図を生成し、グラフのいくつかのプロパティを変更するExcel VBAコードを書きました。コードは、グラフの凡例の削除、水平/垂直グリッド線の削除、XおよびYシリーズの変更などのタスクをゆっくりと移動します。 Excelのタイマーは私に、タスクごとに、次の期間を与える:VBA Chart操作が遅い
insert scatterplot: 0.01171875
delete series: 0
plot x vs y: 0.55859375
delete legend: 0.5703125
delete chart title: 0.66015625
remove grid: 1.3046875
format axes: 0
overall: 3.11328125
、グリッドを削除するタイトルを変更し、XとYシリーズをプロットし、凡例を削除するには長い時間がかかるように見えます。私は、コードを書く代わりの方法を探ってきたが、何か有用なものを見つけることができなかった。遅い速度を除いて、コードは完全に期待通りに機能します。何が悪いパフォーマンスを引き起こしているか、どのように私はこれをスピードアップすることができますか?前もって感謝します。
EDIT:チャートの操作中に画面の更新を無効にしました。チャートは、ユーザーフォームが開いている間に生成/書式設定されます。ここにあなたが持っているコードの一部にはいくつかの選択肢があるが、これが遅い理由を言うのは難しいことができ、データおよび機械の仕様がなければ
With ActiveChart
'Delete all series currently in plot
Do While .FullSeriesCollection.Count > 0
.FullSeriesCollection(1).Delete
Loop
'Plot Actual (Y) vs. Inverse Distribution (X)
.SeriesCollection.NewSeries
.FullSeriesCollection(1).XValues = "=" & tempSheetName & "!$C:$C"
.FullSeriesCollection(1).Values = "=" & tempSheetName & "!$A:$A"
'Delete legend
.Legend.Delete
'Delete chart title
.SetElement (msoElementChartTitleNone)
'Remove gridlines
.SetElement (msoElementPrimaryValueGridLinesNone)
.SetElement (msoElementPrimaryCategoryGridLinesNone)
'Format axes
Dim xAxis As Axis, yAxis As Axis
Set xAxis = .Axes(xlCategory)
Set yAxis = .Axes(xlValue)
With yAxis
'Title y axis "actual"
.HasTitle = True
.AxisTitle.Caption = "Actual"
'Add tick marks
.MajorTickMark = xlOutside
End With
With xAxis
'Title x axis by dist type
.HasTitle = True
.AxisTitle.Caption = dist.getDistType
'Add tick marks
.MajorTickMark = xlOutside
End With
End With
ブックのサンプルを投稿できますか? – brettdj