大規模なデータセットで最適化タスクを実行すると、オーバーフロー ランタイム エラー 6 がときどき発生します (通常は 1 時間または 2 時間後)。マクロを停止したところから再起動すると、エラーはなくなります。つまり、エラーが発生した場所からマクロを再度起動します。オーバーフロー エラーは、使用後に適切に破棄されないオブジェクトを作成しすぎたという問題に関連している可能性がありますか?
これは私のコンテナー クラスの (簡略化されたバージョン) で、何千回も (Set ... = Nothing を介して) 破棄され、(Set ... = New を介して) 再構築されます。
'CG_data_point custom collection class
Public data_points As Collection
Private Sub Class_Initialize()
Set data_points = New Collection
End Sub
Public Sub AddDataPoint(mydate as date, price as double)
Dim new_data_point As CG_data_point
Set new_data_point = New CG_data_point
new_data_point.EnterData mydate, price
data_points.Add new_data_point
Set new_data_point = Nothing 'I assume this one could also be skipped
End Sub
Public Sub RMSE(X as double) as double
...
End Sub
Private Sub Class_Terminate()
Dim data_point As CG_data_point
For Each data_point In data_points 'destruct each data point individually
Set data_point = Nothing
Next data_point
Set data_points = Nothing
End Sub
'Main module
dim global_container as CG_data_container
sub do_optimizations()
Do
set global_container= new CG_data_container
.... do something with the data, have in call to global function RMSE_UDF as a cell formula for Solver
set global_container= nothing
While (...)
end sub
'worksheet function
function RMSE_UDF(X as double)
global_container.RMSE(X)
end function
コンテナー変数 global_container は、ワークシート UDF (RMSE_UDF) から呼び出すことができる必要があるため、グローバルである必要があります。私の知る限り、ワークシートの数式は、「=RMSE(MyContainer,...)」のようにオブジェクトを引数として持つことはできません。二乗平均平方根誤差 (RMSE) の最小化は、Excel ソルバーで実行されます。