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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The error means that there is no named range propoffer in the scope of the active worksheet.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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