Hi,
There's one thing to consider before using VBA for this. The way our add-in works, we only store values that we think you want. That's the "reference cell" concept we talk about in the help files. That may be why you're not getting the right values - if there's no reference cell, we may not be storing them.
To work around that, just make sure you have a cell in your spreadsheet with some statistics function, like SimulationMean, referring to the cell you want to work with. This is kind of annoying but it's simple enough. You can have as many of these as you need.
So let's assume you're modeling the values in cell C5. In the spreadsheet, put another cell with
=SimulationMean( C5 )
Then you can be sure it will be available in VBA.
To get the whole list as an array, you can use the function
=SimulationValuesArray( C5 )
That will return the whole set. From VBA, you have to use either the Application.ExecuteExcel4Macro syntax or the Application.Run syntax. The end result will look like this:
---
Sub TestValues()
' create an array first, but leave the size blank.
Dim v() As Variant
' get the values
v = Application.Run("SimulationValuesArray", Range("C5"))
' check the size of the array: should be the same as the
' number of trials from the last run
MsgBox "Size? " & UBound(vx)
' use some worksheet function: here, the mean. compare
' this with the mean reported in the worksheet.
MsgBox "Average? " & Application.WorksheetFunction.Average(vx)
End Sub
---
If you did want to get just one value, you can use the same syntax with the SimulationValue function; for example,
...
dim d as double
d = Application.Run("SimulationValue", Range("C5"), 1 )
...
Let me know if that works for you.
Cheers,
Alex
support@riskamp.com