code do not respond VBA CODE

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. 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.

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
Thank you for reading this, and thank you If you decide to spent sometime to help me.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Thanks for posting on the forum.

Check if the following is what you need:
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 For
            End If
        Next l
        If j > 5 Then Exit For
    Next k
    
    Range("F2").Resize(20, 5).Value = arr
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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