Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
all permutations
Hi. I am trying to generate all possible single arrays which consist of one
element in each row of a double array in VisualBasic in Excel. For example, if DoubleArray(R,C) is first row 1,2,3 and second row 4,5,6; then I want NewArray(R) of (1,4), (1,5), (1,6), (2,4), (2,5) and (2,6). I have figured out how to do this with specific numbers of rows and columns, but I want to do this with a variable number of rows and columns (input by the user). Here is what I have: If Rows = 3 Then For i = 1 To Columns For j = 1 To Columns For k = 1 To Columns NewArray(1) = DoubleArray(1, i) NewArray (2) = DoubleArray(2, j) NewArray (3) = DoubleArray(3, k) Functions Next k Next j Next i ElseIf Rows = 4 Then For i = 1 To Columns €¦ End If 'Functions' are simply what I want to do with the single arrays. How can I change this so it can work with any number of rows and columns? Thanks for any help. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
all permutations
Dim NewArray As Variant
NumberofRows = UBound(DoubleArray, 1) NumberofCols = UBound(DoubleArray, 2) NewArrayIndex = 1 ReDim NewArray(NumberofRows * NumberofCols) For RowCount = 1 To NumberofRows For ColCount = 1 To NumberofCols NewArray(NewArrayIndex) = _ DoubleArray(RowCount, ColCount) NewArrayIndex = NewArrayIndex + 1 Next ColCount Next RowCount "KAH" wrote: Hi. I am trying to generate all possible single arrays which consist of one element in each row of a double array in VisualBasic in Excel. For example, if DoubleArray(R,C) is first row 1,2,3 and second row 4,5,6; then I want NewArray(R) of (1,4), (1,5), (1,6), (2,4), (2,5) and (2,6). I have figured out how to do this with specific numbers of rows and columns, but I want to do this with a variable number of rows and columns (input by the user). Here is what I have: If Rows = 3 Then For i = 1 To Columns For j = 1 To Columns For k = 1 To Columns NewArray(1) = DoubleArray(1, i) NewArray (2) = DoubleArray(2, j) NewArray (3) = DoubleArray(3, k) Functions Next k Next j Next i ElseIf Rows = 4 Then For i = 1 To Columns €¦ End If 'Functions' are simply what I want to do with the single arrays. How can I change this so it can work with any number of rows and columns? Thanks for any help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Permutations | Excel Worksheet Functions | |||
permutations | Excel Worksheet Functions | |||
permutations | Excel Discussion (Misc queries) | |||
Permutations | Excel Worksheet Functions | |||
Permutations | Excel Worksheet Functions |