its_me_renan
Board Regular
- Joined
- Dec 18, 2011
- Messages
- 70
Below is the program that generates 20 number combination and each combination was written on column C to V. Can you please help me to edit this program in order to generate 20 number combination from 50 numbers (50C20) in which upon reaching the last row of excel (row 1048576) it will automatically proceed to other column let say column X to AQ. If sheet 1 is fully filled up it will proceeed to other sheets. Thank you.
[TABLE="width: 416"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer, G As Integer, H As Integer, I As Integer, J As Integer, K As Integer, L As Integer, M As Integer, N As Integer, O As Integer, P As Integer, Q As Integer, R As Integer, S As Integer, T As Integer, U As Integer[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Dim nNb() As Integer, V As Integer, X As Double[/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]Sub GetCombin()[/TD]
[/TR]
[TR]
[TD]' Program to generate 20-number combinations[/TD]
[/TR]
[TR]
[TD]Application.ScreenUpdating = False[/TD]
[/TR]
[TR]
[TD]ReDim nNb(27)[/TD]
[/TR]
[TR]
[TD]Range("A1").Select[/TD]
[/TR]
[TR]
[TD]V = 1[/TD]
[/TR]
[TR]
[TD]' Allow up to 27 numbers starting in A1 and descending[/TD]
[/TR]
[TR]
[TD]Do Until V = 28[/TD]
[/TR]
[TR]
[TD]If ActiveCell.Offset(V - 1, 0) = "" Then Exit Do[/TD]
[/TR]
[TR]
[TD]nNb(V) = ActiveCell.Offset(V - 1, 0).Value[/TD]
[/TR]
[TR]
[TD]V = V + 1[/TD]
[/TR]
[TR]
[TD]Loop[/TD]
[/TR]
[TR]
[TD]ReDim Preserve nNb(V)[/TD]
[/TR]
[TR]
[TD]V = V - 1[/TD]
[/TR]
[TR]
[TD]X = 1[/TD]
[/TR]
[TR]
[TD]' Place combinations in columns C to V starting at row 2[/TD]
[/TR]
[TR]
[TD]For A = 1 To V - 19[/TD]
[/TR]
[TR]
[TD]For B = A + 1 To V - 18[/TD]
[/TR]
[TR]
[TD]For C = B + 1 To V - 17[/TD]
[/TR]
[TR]
[TD]For D = C + 1 To V - 16[/TD]
[/TR]
[TR]
[TD]For E = D + 1 To V - 15[/TD]
[/TR]
[TR]
[TD]For F = E + 1 To V - 14[/TD]
[/TR]
[TR]
[TD]For G = F + 1 To V - 13[/TD]
[/TR]
[TR]
[TD]For H = G + 1 To V - 12[/TD]
[/TR]
[TR]
[TD]For I = H + 1 To V - 11[/TD]
[/TR]
[TR]
[TD]For J = I + 1 To V - 10[/TD]
[/TR]
[TR]
[TD]For K = J + 1 To V - 9[/TD]
[/TR]
[TR]
[TD]For L = K + 1 To V - 8[/TD]
[/TR]
[TR]
[TD]For M = L + 1 To V - 7[/TD]
[/TR]
[TR]
[TD]For N = M + 1 To V - 6[/TD]
[/TR]
[TR]
[TD]For O = N + 1 To V - 5[/TD]
[/TR]
[TR]
[TD]For P = O + 1 To V - 4[/TD]
[/TR]
[TR]
[TD]For Q = P + 1 To V - 3[/TD]
[/TR]
[TR]
[TD]For R = Q + 1 To V - 2[/TD]
[/TR]
[TR]
[TD]For S = R + 1 To V - 1[/TD]
[/TR]
[TR]
[TD]For T = S + 1 To V[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 2).Value = nNb(A)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 3).Value = nNb(B)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 4).Value = nNb(C)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 5).Value = nNb(D)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 6).Value = nNb(E)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 7).Value = nNb(F)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 8).Value = nNb(G)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 9).Value = nNb(H)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 10).Value = nNb(I)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 11).Value = nNb(J)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 12).Value = nNb(K)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 13).Value = nNb(L)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 14).Value = nNb(M)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 15).Value = nNb(N)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 16).Value = nNb(O)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 17).Value = nNb(P)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 18).Value = nNb(Q)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 19).Value = nNb(R)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 20).Value = nNb(S)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 21).Value = nNb(T)[/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]X = X + 1[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Next T[/TD]
[/TR]
[TR]
[TD]Next S[/TD]
[/TR]
[TR]
[TD]Next R[/TD]
[/TR]
[TR]
[TD]Next Q[/TD]
[/TR]
[TR]
[TD]Next P[/TD]
[/TR]
[TR]
[TD]Next O[/TD]
[/TR]
[TR]
[TD]Next N[/TD]
[/TR]
[TR]
[TD]Next M[/TD]
[/TR]
[TR]
[TD]Next L[/TD]
[/TR]
[TR]
[TD]Next K[/TD]
[/TR]
[TR]
[TD]Next J[/TD]
[/TR]
[TR]
[TD]Next I[/TD]
[/TR]
[TR]
[TD]Next H[/TD]
[/TR]
[TR]
[TD]Next G[/TD]
[/TR]
[TR]
[TD]Next F[/TD]
[/TR]
[TR]
[TD]Next E[/TD]
[/TR]
[TR]
[TD]Next D[/TD]
[/TR]
[TR]
[TD]Next C[/TD]
[/TR]
[TR]
[TD]Next B[/TD]
[/TR]
[TR]
[TD]Next A[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Application.ScreenUpdating = True[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 416"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer, G As Integer, H As Integer, I As Integer, J As Integer, K As Integer, L As Integer, M As Integer, N As Integer, O As Integer, P As Integer, Q As Integer, R As Integer, S As Integer, T As Integer, U As Integer[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Dim nNb() As Integer, V As Integer, X As Double[/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]Sub GetCombin()[/TD]
[/TR]
[TR]
[TD]' Program to generate 20-number combinations[/TD]
[/TR]
[TR]
[TD]Application.ScreenUpdating = False[/TD]
[/TR]
[TR]
[TD]ReDim nNb(27)[/TD]
[/TR]
[TR]
[TD]Range("A1").Select[/TD]
[/TR]
[TR]
[TD]V = 1[/TD]
[/TR]
[TR]
[TD]' Allow up to 27 numbers starting in A1 and descending[/TD]
[/TR]
[TR]
[TD]Do Until V = 28[/TD]
[/TR]
[TR]
[TD]If ActiveCell.Offset(V - 1, 0) = "" Then Exit Do[/TD]
[/TR]
[TR]
[TD]nNb(V) = ActiveCell.Offset(V - 1, 0).Value[/TD]
[/TR]
[TR]
[TD]V = V + 1[/TD]
[/TR]
[TR]
[TD]Loop[/TD]
[/TR]
[TR]
[TD]ReDim Preserve nNb(V)[/TD]
[/TR]
[TR]
[TD]V = V - 1[/TD]
[/TR]
[TR]
[TD]X = 1[/TD]
[/TR]
[TR]
[TD]' Place combinations in columns C to V starting at row 2[/TD]
[/TR]
[TR]
[TD]For A = 1 To V - 19[/TD]
[/TR]
[TR]
[TD]For B = A + 1 To V - 18[/TD]
[/TR]
[TR]
[TD]For C = B + 1 To V - 17[/TD]
[/TR]
[TR]
[TD]For D = C + 1 To V - 16[/TD]
[/TR]
[TR]
[TD]For E = D + 1 To V - 15[/TD]
[/TR]
[TR]
[TD]For F = E + 1 To V - 14[/TD]
[/TR]
[TR]
[TD]For G = F + 1 To V - 13[/TD]
[/TR]
[TR]
[TD]For H = G + 1 To V - 12[/TD]
[/TR]
[TR]
[TD]For I = H + 1 To V - 11[/TD]
[/TR]
[TR]
[TD]For J = I + 1 To V - 10[/TD]
[/TR]
[TR]
[TD]For K = J + 1 To V - 9[/TD]
[/TR]
[TR]
[TD]For L = K + 1 To V - 8[/TD]
[/TR]
[TR]
[TD]For M = L + 1 To V - 7[/TD]
[/TR]
[TR]
[TD]For N = M + 1 To V - 6[/TD]
[/TR]
[TR]
[TD]For O = N + 1 To V - 5[/TD]
[/TR]
[TR]
[TD]For P = O + 1 To V - 4[/TD]
[/TR]
[TR]
[TD]For Q = P + 1 To V - 3[/TD]
[/TR]
[TR]
[TD]For R = Q + 1 To V - 2[/TD]
[/TR]
[TR]
[TD]For S = R + 1 To V - 1[/TD]
[/TR]
[TR]
[TD]For T = S + 1 To V[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 2).Value = nNb(A)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 3).Value = nNb(B)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 4).Value = nNb(C)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 5).Value = nNb(D)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 6).Value = nNb(E)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 7).Value = nNb(F)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 8).Value = nNb(G)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 9).Value = nNb(H)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 10).Value = nNb(I)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 11).Value = nNb(J)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 12).Value = nNb(K)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 13).Value = nNb(L)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 14).Value = nNb(M)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 15).Value = nNb(N)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 16).Value = nNb(O)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 17).Value = nNb(P)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 18).Value = nNb(Q)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 19).Value = nNb(R)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 20).Value = nNb(S)[/TD]
[/TR]
[TR]
[TD]ActiveCell.Offset(X, 21).Value = nNb(T)[/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD]X = X + 1[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Next T[/TD]
[/TR]
[TR]
[TD]Next S[/TD]
[/TR]
[TR]
[TD]Next R[/TD]
[/TR]
[TR]
[TD]Next Q[/TD]
[/TR]
[TR]
[TD]Next P[/TD]
[/TR]
[TR]
[TD]Next O[/TD]
[/TR]
[TR]
[TD]Next N[/TD]
[/TR]
[TR]
[TD]Next M[/TD]
[/TR]
[TR]
[TD]Next L[/TD]
[/TR]
[TR]
[TD]Next K[/TD]
[/TR]
[TR]
[TD]Next J[/TD]
[/TR]
[TR]
[TD]Next I[/TD]
[/TR]
[TR]
[TD]Next H[/TD]
[/TR]
[TR]
[TD]Next G[/TD]
[/TR]
[TR]
[TD]Next F[/TD]
[/TR]
[TR]
[TD]Next E[/TD]
[/TR]
[TR]
[TD]Next D[/TD]
[/TR]
[TR]
[TD]Next C[/TD]
[/TR]
[TR]
[TD]Next B[/TD]
[/TR]
[TR]
[TD]Next A[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Application.ScreenUpdating = True[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]