Distribute known numbers into columns using VBA

Luthius

Active Member
Joined
Apr 5, 2011
Messages
324
I have 2 set of numbers that I would like to mix them.
My first set contains 15 numbers that I would like to combine with a set of 10 numbers and distribute them into colunms.
From the set of 15 numbers, the code will choose 9 numbers (randomly) and combine with 5 numbers from the set of 10 numbers (randomly). It will generate a new set of 15 numbers (9 from my first set combined with 05 of the second set of numbers).


I know that it will generate a huge quantity of group of 15 numbers combined, but I would like to delimite in the code, by input box or something.

1st Set with 15 unique Numbers (Range B2:P2)
2nd Set with 09 unique Numbers (Range B3:k3)

Distribution will occur starting on row number 5 and distributed from Column A to Column O.

Luthius
 
Re: How to distribute known numbers into columns using VBA

───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Re: How to distribute known numbers into columns using VBA

Your code is amazing, but it takes a while to run when there are too many groups to be generated.

I would like to share with you a code and at the same time request assistance on how to make some changes in this code to try merge it with your solution.

The code I found on https://www.get-digital-help.com/201...-combinations/, but instead an UDF I would like to make as was done before.


Code:
[COLOR=#333333]Public result() As Variant[/COLOR]Function Combinations(rng As Range, n As Single)

rng1 = rng.Value

ReDim result(n - 1, 0)
    
Call Recursive(rng1, n, 1, 0)

ReDim Preserve result(UBound(result, 1), UBound(result, 2) - 1)
Combinations = Application.Transpose(result)
End Function


Function Recursive(r As Variant, c As Single, d As Single, e As Single)
Dim f As Single

For f = d To UBound(r, 1)
    result(e, UBound(result, 2)) = r(f, 1)
    If e = (c - 1) Then
        ReDim Preserve result(UBound(result, 1), UBound(result, 2) + 1)  
        For g = 0 To UBound(result, 1)
            result(g, UBound(result, 2)) = result(g, UBound(result, 2) - 1)
        Next g
    Else
        Call Recursive(r, c, f + 1, e + 1)
    End If    
Next f [COLOR=#333333]End Function[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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