Help with monte carlo simulation

michaelsmith559

Well-known Member
Joined
Oct 6, 2013
Messages
881
Office Version
  1. 2013
  2. 2007
I have a macro that runs a monte carlo simulation that was working. I changed the values in column o and calculated new probabilities. Now when I run the macro it says the probability column must sum to 1. I have checked where I got the data from and all values and counts are correct but it will not sum to 100%, it only sums to 99%. I have even added a dummy variable to column o and added the 1% but it still says column must sum to 1. Anyhow, can someone help me correct the macro or offer a different macro to do what I want. My macro is somewhat slow. This macro uses the data analysis random number generator in a loop. Here is the code:
Code:
Sub RandomNumberTrials()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i As Integer
For i = 1 To 184
     Application.Run "ATPVBAEN.XLAM!Random", ActiveSheet.Range("$Q$2:$Q$185"), 1, 184 _
        , 7, , ActiveSheet.Range("$O$2:$P$30")
     Application.SendKeys "{Enter}", True
    Range("U1048576").Select
    ActiveCell.End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = Range("Q2").End(xlDown).Value
    Next i
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Here is a screenshot:

Excel 2012
NOP
1CountCombineProb
261113%
3151128%
4131137%
531142%
671244%
771254%
892165%
9132177%
1032182%
11102285%
1282294%
131331107%
14231111%
1583194%
16832114%
17132121%
18841124%
19441132%
20742134%
21142141%
221151146%
23152141%
24652153%
25361152%
26262161%
27671163%
28172161%
29381162%
30391172%
Predictors Pos 1
Cell Formulas
RangeFormula
N2=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O2)
N3=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O3)
N4=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O4)
N5=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O5)
N6=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O6)
N7=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O7)
N8=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O8)
N9=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O9)
N10=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O10)
N11=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O11)
N12=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O12)
N13=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O13)
N14=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O14)
N15=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O15)
N16=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O16)
N17=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O17)
N18=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O18)
N19=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O19)
N20=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O20)
N21=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O21)
N22=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O22)
N23=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O23)
N24=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O24)
N25=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O25)
N26=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O26)
N27=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O27)
N28=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O28)
N29=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O29)
N30=COUNTIF(INDIRECT("M2:M"&COUNTA(M:M)),O30)
P2=N2/$D$14
P3=N3/$D$14
P4=N4/$D$14
P5=N5/$D$14
P6=N6/$D$14
P7=N7/$D$14
P8=N8/$D$14
P9=N9/$D$14
P10=N10/$D$14
P11=N11/$D$14
P12=N12/$D$14
P13=N13/$D$14
P14=N14/$D$14
P15=N15/$D$14
P16=N16/$D$14
P17=N17/$D$14
P18=N18/$D$14
P19=N19/$D$14
P20=N20/$D$14
P21=N21/$D$14
P22=N22/$D$14
P23=N23/$D$14
P24=N24/$D$14
P25=N25/$D$14
P26=N26/$D$14
P27=N27/$D$14
P28=N28/$D$14
P29=N29/$D$14
P30=N30/$D$14
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,

I am not a Monte Carlo Analysis expert - but I have visited the principality if that counts :)

However, there are a couple of things I noticed. Firstly, there is an easier way to append numbers to a list but before pursuing that, can you not use the complete list of numbers returned by the Analysis Add-In? Why do you get it to create 184 numbers then use only the last one then repeat the process 184 times?

Also, when I used your numbers, the Add-In worked without complaint and produced a list of numbers. So I decided to delve deeper and see if I could re-create what you might have started from using the formulas in your question and that is where I started getting inconsistencies.

For instance, the total of the numbers in column N is 182 not 184.

Looking at the COUNTIF formulas you count all the numbers in column M but then start the comparisons at M2 which ignores one of the numbers in the count. So even if column M has a heading that means there is a count of 183 and only 182 numbers but you are trying for 184.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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