Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mac Mac is offline
external usenet poster
 
Posts: 213
Default Generating pairs from a given set

I have a column with 15 values and from these values I need a list of all
non-repeating pairs possible. Simple task, but for us not-so-well-versed in
the Excel development environment - is there a code sample? Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Generating pairs from a given set



Hi,

This assumes your 15 numbers are in the range A1 to A15. Right click the
sheet tab, view code and paste this in and run it:-

Sub permem()
Dim count, perms As Long
count = 1
Dim myRange As Range
Set myRange = Range("A1:A15")
numbers = 15
Dim n(15)
For p = 1 To numbers
n(p) = Cells(p, 1).Value
Next
For i = 1 To numbers
For j = 1 To numbers
If j <= i Then GoTo 100
For x = 1 To numbers
If i = x Then firstno = n(x)
Next
For x = 1 To numbers
If j = x Then secondno = n(x)
Next
Cells(count, 3).Value = firstno & ", " & secondno
count = count + 1
100 Next
Next

End Sub


Mike

"Mac" wrote:

I have a column with 15 values and from these values I need a list of all
non-repeating pairs possible. Simple task, but for us not-so-well-versed in
the Excel development environment - is there a code sample? Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
Mac Mac is offline
external usenet poster
 
Posts: 213
Default Generating pairs from a given set

Mike, you're the expert I needed.:-) Now there's another step I'd like to
perform on this data;
Assume I have applied your code (this time on 14 values in a column), so now
I have 91 value pairs. Next, from these 91 pairs, I need to generate all
possible sets, where each set conforms to the following criteria:
1.the set (that is - the 7 pairs in the set) contains all numbers from the
original 14
2. no number is repeated throughout the set
Imagine a tennis tournament; you have 14 players and you want all of them to
play in each round (7 matches per round) until each player has played all the
others.
Again - this a simple combinatorics task but for an Excel expert like you
only. Can you help once more?:-)

"Mike H" wrote:



Hi,

This assumes your 15 numbers are in the range A1 to A15. Right click the
sheet tab, view code and paste this in and run it:-

Sub permem()
Dim count, perms As Long
count = 1
Dim myRange As Range
Set myRange = Range("A1:A15")
numbers = 15
Dim n(15)
For p = 1 To numbers
n(p) = Cells(p, 1).Value
Next
For i = 1 To numbers
For j = 1 To numbers
If j <= i Then GoTo 100
For x = 1 To numbers
If i = x Then firstno = n(x)
Next
For x = 1 To numbers
If j = x Then secondno = n(x)
Next
Cells(count, 3).Value = firstno & ", " & secondno
count = count + 1
100 Next
Next

End Sub


Mike

"Mac" wrote:

I have a column with 15 values and from these values I need a list of all
non-repeating pairs possible. Simple task, but for us not-so-well-versed in
the Excel development environment - is there a code sample? Thanks!

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
Finding pairs of numbers Iriemon Excel Worksheet Functions 2 February 3rd 10 09:20 PM
How to delete pairs Salman Excel Discussion (Misc queries) 9 April 1st 09 07:06 PM
finding pairs Len Case Excel Worksheet Functions 5 December 18th 07 07:34 PM
Counting pairs Piotrek Excel Worksheet Functions 8 August 21st 07 09:32 PM
Pairs, Triplets, Quads... Mike NG Excel Programming 10 June 5th 05 06:48 PM


All times are GMT +1. The time now is 12:40 PM.

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

About Us

"It's about Microsoft Excel"