HI,
I found this VB code in Mrexcel archive and written by "PGC01"
its wounderful and fast but i have "Runtime error 1004" or error 400
"Method Range of object_Global failed", and it Highlight this line
when it reaches to the last row.
is it possible to amend the code so it can continue on the next column.
This is the code;
<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 4 15</TD><TD style="TEXT-ALIGN: right">3</TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 3 6 8</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 5 10</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 3 7 12</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 6 8</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 3 9 14</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 7 12</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 3 11 13</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 9 14</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 4 5 11</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 3 11 13</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 4 6 13</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD style="FONT-SIZE: 10pt; FONT-FAMILY: Arial Unicode MS">1 2 4 5 11</TD><TD> </TD><TD>1 2 3 4 15</TD><TD>1 2 3 5 10</TD><TD>1 2 4 7 14</TD></TR></TBODY></TABLE>
thanks for any assistance
Sezuh
I found this VB code in Mrexcel archive and written by "PGC01"
its wounderful and fast but i have "Runtime error 1004" or error 400
"Method Range of object_Global failed", and it Highlight this line
when it reaches to the last row.
HTML:
Range("C" & lRow).Resize(, p) = vresult
This is the code;
Code:
[COLOR=black][FONT=Courier New]Sub [/FONT][/COLOR][B][COLOR=red][FONT=Courier New]Combinations[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New]()<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim rRng As Range, p As Integer<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim vElements, lRow As Long, vresult As Variant<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set rRng = Range("A1", Range("A1").End(xlDown)) ' The set of numbers <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]p = Range("B1").Value ' How many are picked <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]vElements = Application.Index(Application.Transpose(rRng), 1, 0)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]ReDim vresult(1 To p)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Columns("C").Resize(, p + 1).Clear<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Call CombinationsNP(vElements, p, vresult, lRow, 1, 1)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]End Sub<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim i As Integer<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]<o:p> </o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]For i = iElement To UBound(vElements)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] vresult(iIndex) = vElements(i)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] If iIndex = p Then<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] lRow = lRow + 1<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] Range("C" & lRow).Resize(, p) = vresult<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] Else<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] Call CombinationsNP(vElements, p, vresult, lRow, i + 1, iIndex + 1)<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] End If<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Next i<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End Sub[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman][/FONT][/COLOR]
thanks for any assistance
Sezuh