montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 984
- Office Version
- 2010
- Platform
- Windows
Hello guys,
I am re-working about this:
There are 12 numbers at A1:A12 the action require is to generates an array of size 20 x 5 with the specified occurrence for each location (“ or whatever is here could be letters etc.”). A1=8, A2=7, A3=9, A4=10, A5=11, A6=10, A7=11, A8=7, A9=6, A10=5, A11=7, A12=9. The numbers that illustrated the occurrences of this numbers are at B1:B12 accordingly with the set on A1:A12 obviously The array is then displayed at cells F2:J21
The real point here is to have the occurrence control of the column B, meaning I would like to change this values anytime.
Thank you for reading this, and thank you If you decide to spent sometime to help me.
I am re-working about this:
There are 12 numbers at A1:A12 the action require is to generates an array of size 20 x 5 with the specified occurrence for each location (“ or whatever is here could be letters etc.”). A1=8, A2=7, A3=9, A4=10, A5=11, A6=10, A7=11, A8=7, A9=6, A10=5, A11=7, A12=9. The numbers that illustrated the occurrences of this numbers are at B1:B12 accordingly with the set on A1:A12 obviously The array is then displayed at cells F2:J21
The real point here is to have the occurrence control of the column B, meaning I would like to change this values anytime.
VBA Code:
Sub Montecarlo_combin()
Dim arr(1 To 20, 1 To 5) As Variant
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
i = 1
j = 1
For k = 1 To 12
For l = 1 To Range("B" & k).Value
arr(i, j) = Range("A" & k).Value
i = i + 1
If i > 20 Then
i = 1
j = j + 1
If j > 5 Then Exit Sub
End If
Next l
Next k
Range("F2").Resize(20, 5).Value = arr
End Sub