Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Combination of given numbers

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?
  #3   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Combination of given numbers

You could try a macro. Assuming the 12 items are on Sheet1 in cells A1:A12
and you want the list on Sheet2, starting in cell A2 - this appears to give
the results you want:

Sub ListCombinations()
Dim rngList As Range
Dim wksDest As Worksheet
Dim a As Long, b As Long, c As Long
Dim d As Long, e As Long, f As Long
Dim lngElements As Long

Set rngList = Sheet1.Range("A1:A12")
Set wksDest = Sheet2
lngElements = rngList.Cells.Count

For a = 1 To lngElements - 5
For b = a + 1 To lngElements - 4
For c = b + 1 To lngElements - 3
For d = c + 1 To lngElements - 2
For e = d + 1 To lngElements - 1
For f = e + 1 To lngElements
wksDest.Cells(Rows.Count, 1).End(xlUp)(2, 1).Value = _
rngList(a) & ", " & rngList(b) & ", " & rngList(c) & ", " & _
rngList(d) & ", " & rngList(e) & ", " & rngList(f)
Next f
Next e
Next d
Next c
Next b
Next a
End Sub


"Rendar" wrote:

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Combination of given numbers

Thank you very much it works.
Although ,I forgot to mention that I would like to see the other 6 numbers
not in the group of 6 as well for each combination.

"Rendar" wrote:

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?

  #5   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Combination of given numbers

If the list is in A2:A925, try this in B2 and copy down

=INDEX(A$2:A$925,COUNTA(A2:A$925))

So for A2 it will return the item in A925, for A3 it will return A924 (ie
the formula takes the existing list and inverts the order which I believe
will give you want you want).


"Rendar" wrote:

Thank you very much it works.
Although ,I forgot to mention that I would like to see the other 6 numbers
not in the group of 6 as well for each combination.

"Rendar" wrote:

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Combination of given numbers

How about if your data set has 519 records and you want all combinations of
numbers that add up to 32347.79?

"JMB" wrote:

You could try a macro. Assuming the 12 items are on Sheet1 in cells A1:A12
and you want the list on Sheet2, starting in cell A2 - this appears to give
the results you want:

Sub ListCombinations()
Dim rngList As Range
Dim wksDest As Worksheet
Dim a As Long, b As Long, c As Long
Dim d As Long, e As Long, f As Long
Dim lngElements As Long

Set rngList = Sheet1.Range("A1:A12")
Set wksDest = Sheet2
lngElements = rngList.Cells.Count

For a = 1 To lngElements - 5
For b = a + 1 To lngElements - 4
For c = b + 1 To lngElements - 3
For d = c + 1 To lngElements - 2
For e = d + 1 To lngElements - 1
For f = e + 1 To lngElements
wksDest.Cells(Rows.Count, 1).End(xlUp)(2, 1).Value = _
rngList(a) & ", " & rngList(b) & ", " & rngList(c) & ", " & _
rngList(d) & ", " & rngList(e) & ", " & rngList(f)
Next f
Next e
Next d
Next c
Next b
Next a
End Sub


"Rendar" wrote:

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?

  #7   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Combination of given numbers

I think that many records will require more power than XL can bring to the
table. I'd expect XL will crash.

For XL combination solutions, I think most folks recommend Harlan's macro.
Go to Google and search on "findsums". The only caveat is if the first n
numbers in your series happen to total the number you want, I think it misses
that particular combination. Also, I think it stops after it fills up an
entire column of one worksheet.

But that will most likely work only for a *much* smaller data set. Most XL
solutions I've seen are only for data sets around 30.

"Dan O''''Connell" wrote:

How about if your data set has 519 records and you want all combinations of
numbers that add up to 32347.79?

"JMB" wrote:

You could try a macro. Assuming the 12 items are on Sheet1 in cells A1:A12
and you want the list on Sheet2, starting in cell A2 - this appears to give
the results you want:

Sub ListCombinations()
Dim rngList As Range
Dim wksDest As Worksheet
Dim a As Long, b As Long, c As Long
Dim d As Long, e As Long, f As Long
Dim lngElements As Long

Set rngList = Sheet1.Range("A1:A12")
Set wksDest = Sheet2
lngElements = rngList.Cells.Count

For a = 1 To lngElements - 5
For b = a + 1 To lngElements - 4
For c = b + 1 To lngElements - 3
For d = c + 1 To lngElements - 2
For e = d + 1 To lngElements - 1
For f = e + 1 To lngElements
wksDest.Cells(Rows.Count, 1).End(xlUp)(2, 1).Value = _
rngList(a) & ", " & rngList(b) & ", " & rngList(c) & ", " & _
rngList(d) & ", " & rngList(e) & ", " & rngList(f)
Next f
Next e
Next d
Next c
Next b
Next a
End Sub


"Rendar" wrote:

Hello,
I have a list of twelve distinct numbers and would like to somehow display
all distinct combinations of 6 on Excel. The COMBIN function just gives me
the total number of them (924). Is there a way to explicitly show them?

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
How do i zero pad when using combination of text and numbers? kiran cherukumilli New Users to Excel 1 October 5th 06 03:41 PM
matching a combination of numbers mike Excel Discussion (Misc queries) 2 June 28th 06 09:56 PM
combination of numbers dc Excel Discussion (Misc queries) 0 June 8th 06 07:53 PM
How to show all the possible combination of a set of numbers? [email protected] Excel Worksheet Functions 3 February 12th 06 10:29 AM
Total a Combination of Numbers Erika Excel Worksheet Functions 1 April 19th 05 11:10 PM


All times are GMT +1. The time now is 05:31 PM.

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"