Problem with array in VBA - monte carlo simulation

joejackson123

New Member
Joined
Oct 27, 2017
Messages
16
All, I'm trying to do a montecarlo simulation, and have the following code:

Code:
Dim asd As Double
Dim bsd As Double
Dim csd As Double
Dim dsd As Double


Dim xx As Variant
Dim montecarloarray() As Variant


ReDim montecarloarray(1 To 1)


For xx = 1 To 100


asd = Rnd
bsd = Rnd
csd = Rnd
dsd = Rnd


Range("disc").Value = WorksheetFunction.Norm_Inv(asd, 1, 1.67)
Range("cof").Value = WorksheetFunction.Norm_Inv(bsd, 1, 1.67)
Range("syn").Value = WorksheetFunction.Norm_Inv(csd, 1, 1.67)
Range("cash").Value = WorksheetFunction.Norm_Inv(dsd, 1, 1.67)


montecarloarray(UBound(montecarloarray)) = Range("propoffer").Value
ReDim Preserve montecarloarray(1 To UBound(montecarloarray) + 1)


Next xx




Range("ar_2").Resize(UBound(montecarloarray)) = Application.Transpose(montecarloarray)




End Sub

I get a "subscript out of range error" on
Code:
montecarloarray(UBound(montecarloarray)) = Range("propoffer").Value
. How can I fix this? Any help is much appreciated, thank you!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The error means that there is no named range propoffer in the scope of the active worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top