PDA

View Full Version : [SOLVED:] List 4 number combinations



estatefinds
08-10-2016, 04:21 PM
the macro I have now list the combinations 4 number combinations 1,2,3,4,5,6,7,8,9,10, but need this to list numbers using numbers 1,2,3,4,5,6,7,8,9,0. 4 number combinations. in file is attached. Thank you in advance!!:)

mikerickson
08-10-2016, 05:53 PM
I think this will do what you want

Sub test()
Dim i As Long, j As Long, k As Long, m As Long, ii As Long
Dim Letters As Variant
Dim outPut As Variant, Pointer As Long
Dim Low As Long, High As Long

Letters = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
Low = LBound(Letters): High = UBound(Letters)
ReDim outPut(1 To 4, 1 To 1)
For i = Low To High - 3
For j = i + 1 To High - 2
For k = j + 1 To High - 1
For m = k + 1 To High
Pointer = Pointer + 1
If UBound(outPut, 2) < Pointer Then ReDim Preserve outPut(1 To 4, 1 To 2 * Pointer)

outPut(1, Pointer) = Letters(i)
outPut(2, Pointer) = Letters(j)
outPut(3, Pointer) = Letters(k)
outPut(4, Pointer) = Letters(m)

Next
Next k
Next j
Next i

Range("G1").Resize(UBound(outPut, 2), UBound(outPut, 1)).Value = Application.Transpose(outPut)
End Sub

estatefinds
08-10-2016, 06:23 PM
Great work!!! Thank you very much!!!!!:)