Generate number combinations without duplicate pairings

Hi,
I need a VBA code to generate 5 number combinations from 1 to 50 without repeating pairs, order does not matter (ex. combination 1 2 3 4 5, number 1 cannot repeated with numbers 2 3 4 5 in the next combinations)
darren doAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Please show a few examples of what you want.
0
darren doAuthor Commented:
Let's say two combinations 5 8 11 18 20 and 5 7 11 17 21 thats not good because the pair 5 and 11 is repeating I wanna generate combinations without such repeats
Thanks
0
Martin LissOlder than dirtCommented:
This will generate 50 of them. Change the 50's in line 8 and 15 to generate more or less.
Sub RandomPairs()

Dim colR As New Collection
Dim intNum As Integer

Randomize
    
Do Until colR.Count = 50
    intNum = Int(50 * Rnd) + 1
    On Error Resume Next
    colR.Add intNum, Str(intNum)
    On Error GoTo 0
Loop

For intNum = 1 To 50
    Debug.Print colR(intNum)
Next
End Sub

Open in new window

1
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Fabrice LambertFabrice LambertCommented:
Hi,

Maybe with the help of a collection (knowing the key must be unique):
Public Function getSerie() As Collection
On Error GoTo Error
    Dim col As Collection
    Set col = New Collection
    
    Randomize
    Dim i As Integer
    For i = 1 To 5
        Dim number As Integer
tryAgain:
        number = Int(50 * Rnd) + 1
        col.Add number, CStr(number)
    Next
    Set getSerie = col
Exit Function
Error:
    Resume tryAgain
End Function

Open in new window

0
Martin LissOlder than dirtCommented:
Fabrice, what advantage does yours have over mine?
0
Fabrice LambertFabrice LambertCommented:
Only the fact that it is a function returning the collection.

Note: Your solution wasn't showing up when I posted.
0
darren doAuthor Commented:
Martin Liss, thank you for your help.

But how do I get it working?

Thanks
0
Martin LissOlder than dirtCommented:
Try this workbook. Click the 'Generate Pairs' button.
29091733.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertFabrice LambertCommented:
No offences Martin, but I don't think you should take all credit for this.
0
Martin LissOlder than dirtCommented:
No offense taken.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.