Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default multiplying combinations

If I have a list of 8 numbers and want all possible products of all 3 number
combinations, how do I set this up?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default multiplying combinations


Add this function to your workbook:

Code:
--------------------
Public Function NextComboWF(vInx As Variant, n As Long) As Long()
' Worksheet version
' Example usage for 8 choose 4:
' A B C D
' 1 2 3 4 ' literals for first combination
' 1 2 3 5 ' = NextComboWF(A2:D2, 8) array-entered and copied down

' Returns the next combination in lexical order

Dim aiInx() As Long
Dim i As Long
Dim m As Long

m = WorksheetFunction.Count(vInx)

Dim bWrap As Boolean

ReDim aiInx(1 To m)
For i = 1 To m
aiInx(i) = vInx(i)
Next

' set initial combo if empty
If aiInx(1) = 0 Then
For i = 1 To m
aiInx(i) = i
Next i
NextComboWF = aiInx
Exit Function
End If

' find rightmost incrementable index
For i = m To 1 Step -1
If aiInx(i) < n - m + i Then Exit For
Next i

If i = 0 Then
bWrap = True
i = 1
aiInx(1) = 0
End If

' set 'righter' indices sequentially beyond
aiInx(i) = aiInx(i) + 1
For i = i + 1 To m
aiInx(i) = aiInx(i - 1) + 1
Next

NextComboWF = aiInx
End Function
--------------------


In A1, B1, and C1, enter 1, 2, and 3 respectively.

In A2:C2, array enter =NextComboWF(A1:C1, 8) and copy down to row 56.

(Array formulas MUST be confirmed with Ctrl+Shift+Enter, not Enter.
You'll know you did it correctly if curly braces appear around the
formula in the Formula Bar; you cannot type in the braces directly.)


--
shg
------------------------------------------------------------------------
shg's Profile: http://www.thecodecage.com/forumz/member.php?userid=13
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=27126

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,180
Default multiplying combinations

Generate combinations at
http://theory.cs.uvic.ca/~cos/amof/

Copy into Excel 2007.
Easy formulas and no code to write or maintain:
http://www.savefile.com/files/1878334
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
Get rid of #VALUE, after multiplying kbouquet Excel Worksheet Functions 1 March 16th 08 12:24 AM
Multiplying Dave Excel Worksheet Functions 1 November 28th 07 09:27 AM
Permutation combinations and multiplying them Phil Excel Worksheet Functions 5 September 15th 06 06:27 PM
Multiplying BizBroker Excel Discussion (Misc queries) 4 February 7th 06 04:38 PM
Multiplying in a row Daniel - Sydney Excel Discussion (Misc queries) 3 September 27th 05 12:24 AM


All times are GMT +1. The time now is 10:01 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"