Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KAH KAH is offline
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Permutations John[_33_] Excel Worksheet Functions 2 January 31st 10 09:49 PM
permutations art Excel Worksheet Functions 1 May 8th 09 05:07 PM
permutations newyorkjoy Excel Discussion (Misc queries) 3 November 1st 05 08:20 PM
Permutations RedChequer Excel Worksheet Functions 9 September 26th 05 03:14 AM
Permutations RedChequer Excel Worksheet Functions 2 September 25th 05 04:05 AM


All times are GMT +1. The time now is 07:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"