mardi 19 mai 2015

Summing randomly generated values in Excel

I am trying to randomly select values from a short list, sum them, then iterate that process many times. So far I think I am successful in generating the values:

Work so far

                                    0.4855981   0       0       FALSE
        Price                   0.337666609     0       0       FALSE
1       $29.74                  0.808816075     0       0       FALSE
2       $0.85                   0.906751484     0       0       FALSE
3       $38.24                  0.10572928      1       4       17
4       $17                     0.957321497     0       0       FALSE
5       $25.50                  0.644195743     0       0       FALSE
6       $18.70                  0.133302328     0       0       FALSE
7       $29.75                  0.907771163     0       0       FALSE
8       $14.45                  0.156311546     0       0       FALSE
9       $30.60                  0.871958447     0       0       FALSE
10      $26.34                  0.0790938       1       14      24.65
11      $11.05                  0.696383544     0       0       FALSE
12      $124.95                 0.080728462     1       3       38.24
13      $9.35                   0.03717127      1       10      26.34
14      $24.65                  0.970430159     0       0       FALSE
15      $41.65                  0.814402286     0       0       FALSE
                                0.462967917     0       0       FALSE
                                0.646432058     0       0       FALSE
                                0.49384003      0       0       FALSE
                                0.381349746     0       0       FALSE
                                0.129594937     0       0       FALSE
                                0.576582174     0       0       FALSE
                                0.37483142      0       0       FALSE
                                                        
                                                Total   106.23

In any set there are 24 attempts at selecting an item from the price list. What I have done is randomly generate a number and if it less than 0.125 (1/8 chance of getting a value from the price list per attempt) then I generate a random number between 1 and 15 and then vlookup to get the price.

However I want to iterate this process many times, so say out of 100 times each consisting of 24 attempts, what is the average value I return. I cannot find a way to simply add the number to itself each time I update the random numbers, and my VBA is pretty limited - I was considering a loop that has a clickbutton to refresh the numbers. Pseudo code since I know very little VBA:

for 1=1:100
  clickbutton() #to refresh
  grandtotal=grandtotal+total
end

averagevalue=grandtotal/i

I know it seems really easy, but I have not had luck searching how refresh with the clickbutton, or if that is even the best way. Thanks!




Aucun commentaire:

Enregistrer un commentaire