Home

Listing possible combinations

%3CLINGO-SUB%20id%3D%22lingo-sub-707699%22%20slang%3D%22en-US%22%3EListing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-707699%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Experts%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20would%20be%20the%20formula%20for%20Excel%20to%20list%20all%20possible%20combinations%20of%205%20from%20the%20set%20of%206%3F%3C%2FP%3E%3CP%3EI%20have%20attached%20an%20example%20of%20the%20result%20I%20am%20looking%20to%20achieve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EPeter%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-707699%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713350%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713350%22%20slang%3D%22en-US%22%3EI%20see%20you%20haven't%20received%20any%20responses%20so%20far.%20I%20tried%20looking%20at%20your%20sample%20but%20had%20a%20hard%20time%20figuring%20out%20what%20you%20need%20from%20the%20example.%20Perhaps%20you'll%20have%20more%20chance%20on%20a%20solution%20if%20you%20try%20to%20give%20us%20an%20example%20(using%20a%20smaller%20set%20of%20numbers)%20of%20the%20expected%20end%20result%20where%20all%20possible%20combinations%20are%20shown.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713411%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713411%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Jan%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20another%20image%2C%20as%20you%20can%20see%20there%20is%20a%20pool%20of%207%20numbers%20in%20separate%20columns.%20using%20COMBIN%20formula%20will%20say%20there%20are%2021%20possible%20combinations%20of%205%20numbers%20from%20the%20pool%20of%207.%3C%2FP%3E%3CP%3EI%20am%20looking%20for%20a%20formula%20that%20will%20list%20those%20combinations.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EPeter%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713840%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713840%22%20slang%3D%22en-US%22%3E%3CP%3EI%20found%20this%20link%20online%20which%20may%20help.%20It%20is%20basically%20exactly%20what%20you%20want%20but%20it%20uses%20pizza%20ingredients.%20There%20may%20need%20to%20be%20some%20changes%20added%20to%20sum%20the%20numbers.%20I%20can%20try%20it%20out%20myself%20I%20you%20want.%20I%20think%20the%20VBA%20code%20listed%20is%20probably%20needed.%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fwww.get-digital-help.com%2F2015%2F02%2F26%2Freturn-all-combinations%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.get-digital-help.com%2F2015%2F02%2F26%2Freturn-all-combinations%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUpdate!%20Got%20it%20to%20work.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Type%20in%20the%20numbers%2C%20then%20press%20alt%2Bf11%20to%20go%20to%20VBA%20editor.%3C%2FP%3E%3CP%3E2.%20Insert%20-%26gt%3B%20Module%20and%20paste%20the%20code%20below%20in.%3C%2FP%3E%3CP%3E3.%20Go%20back%20to%20Excel%20and%20choose%2021%20rows%20and%205%20columns%20like%20for%20me%20I%20did%20E3-I23%3C%2FP%3E%3CP%3E4.%20Type%20in%20the%20combination%20equation%2C%20hold%20down%20ctl%2Bshift%20and%20press%20enter.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120104i70ADA7FD9D7BB9D3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Screenshot%20(6).png%22%20title%3D%22Screenshot%20(6).png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EHere%20is%20the%20VBA%20Code%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20result()%20As%20Variant%3CBR%20%2F%3E%3CBR%20%2F%3EFunction%20Combinations(rng%20As%20Range%2C%20n%20As%20Single)%3CBR%20%2F%3EDim%20b%20As%20Single%3CBR%20%2F%3E%3CBR%20%2F%3Erng1%20%3D%20rng.Value%3CBR%20%2F%3Eb%20%3D%20WorksheetFunction.Combin(UBound(rng1%2C%201)%2C%20n)%3CBR%20%2F%3E%3CBR%20%2F%3EReDim%20result(b%2C%20n%20-%201)%3CBR%20%2F%3ECall%20Recursive(rng1%2C%20n%2C%201%2C%200%2C%200)%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20g%20%3D%200%20To%20UBound(result%2C%202)%3CBR%20%2F%3Eresult(UBound(result%2C%201)%2C%20g)%20%3D%20%22%22%3CBR%20%2F%3ENext%20g%3CBR%20%2F%3E%3CBR%20%2F%3ECombinations%20%3D%20result%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20Recursive(r%20As%20Variant%2C%20c%20As%20Single%2C%20d%20As%20Single%2C%20e%20As%20Single%2C%20h%20As%20Single)%3CBR%20%2F%3EDim%20f%20As%20Single%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20f%20%3D%20d%20To%20UBound(r%2C%201)%3CBR%20%2F%3E%3CBR%20%2F%3Eresult(h%2C%20e)%20%3D%20r(f%2C%201)%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20e%20%3D%20(c%20-%201)%20Then%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20g%20%3D%200%20To%20UBound(result%2C%202)%3CBR%20%2F%3Eresult(h%20%2B%201%2C%20g)%20%3D%20result(h%2C%20g)%3CBR%20%2F%3ENext%20g%3CBR%20%2F%3Eh%20%3D%20h%20%2B%201%3CBR%20%2F%3EElse%3CBR%20%2F%3ECall%20Recursive(r%2C%20c%2C%20f%20%2B%201%2C%20e%20%2B%201%2C%20h)%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3E%3CBR%20%2F%3ENext%20f%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Function%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713894%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713894%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364542%22%20target%3D%22_blank%22%3E%40crybloodwing%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20this%20software%20but%20it%20doesn't%20work%20for%20this.%3C%2FP%3E%3CP%3EI%20find%20it%20very%20strange%20that%20excel%20can%20calculate%20all%20possible%20combinations%20but%20there%20is%20no%20formula%20to%20list%20those%20combinations.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-713910%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-713910%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F356428%22%20target%3D%22_blank%22%3E%40Peter1550%3C%2FA%3EIt%20did%20list%20the%20combinations%20though...like%20isn't%20the%20list%20of%20numbers%20such%20as%20in%20the%20picture%20in%20the%20E3-I23%20cells%20what%20you%20mean%20by%20listing%3F%20What%20specifically%20are%20you%20looking%20for%20from%20the%20pictures%20you%20posted%3F%20Which%20cells%3F%20And%20the%20VBA%20editor%20software%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-714092%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-714092%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364542%22%20target%3D%22_blank%22%3E%40crybloodwing%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20didn't%20work%20for%20me%20I%20must%20have%20done%20something%20wrong%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-714107%22%20slang%3D%22en-US%22%3ERe%3A%20Listing%20possible%20combinations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-714107%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364542%22%20target%3D%22_blank%22%3E%40crybloodwing%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EStrangely%2C%20I%20receive%20the%20result%20like%20on%20the%20picture%2C%20not%20too%20sure%20what%20did%20I%20do%20wrong%20here%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Peter1550
Occasional Contributor

Hello Experts,

 

What would be the formula for Excel to list all possible combinations of 5 from the set of 6?

I have attached an example of the result I am looking to achieve.

 

Thanks in advance!

 

Regards,

Peter 

7 Replies
I see you haven't received any responses so far. I tried looking at your sample but had a hard time figuring out what you need from the example. Perhaps you'll have more chance on a solution if you try to give us an example (using a smaller set of numbers) of the expected end result where all possible combinations are shown.

@Jan Karel Pieterse 

 

Hi Jan,

 

I have attached another image, as you can see there is a pool of 7 numbers in separate columns. using COMBIN formula will say there are 21 possible combinations of 5 numbers from the pool of 7.

I am looking for a formula that will list those combinations.

 

Thanks.

 

Regards,

Peter

I found this link online which may help. It is basically exactly what you want but it uses pizza ingredients. There may need to be some changes added to sum the numbers. I can try it out myself I you want. I think the VBA code listed is probably needed.




https://www.get-digital-help.com/2015/02/26/return-all-combinations/

 

Update! Got it to work. 

 

1. Type in the numbers, then press alt+f11 to go to VBA editor.

2. Insert -> Module and paste the code below in.

3. Go back to Excel and choose 21 rows and 5 columns like for me I did E3-I23

4. Type in the combination equation, hold down ctl+shift and press enter.

Screenshot (6).png

 

Here is the VBA Code

 

Public result() As Variant

Function Combinations(rng As Range, n As Single)
Dim b As Single

rng1 = rng.Value
b = WorksheetFunction.Combin(UBound(rng1, 1), n)

ReDim result(b, n - 1)
Call Recursive(rng1, n, 1, 0, 0)

For g = 0 To UBound(result, 2)
result(UBound(result, 1), g) = ""
Next g

Combinations = result

End Function

 

Function Recursive(r As Variant, c As Single, d As Single, e As Single, h As Single)
Dim f As Single

For f = d To UBound(r, 1)

result(h, e) = r(f, 1)

If e = (c - 1) Then

For g = 0 To UBound(result, 2)
result(h + 1, g) = result(h, g)
Next g
h = h + 1
Else
Call Recursive(r, c, f + 1, e + 1, h)
End If

Next f

End Function

@crybloodwing

 

I have tried this software but it doesn't work for this.

I find it very strange that excel can calculate all possible combinations but there is no formula to list those combinations.

 

 

@Peter1550It did list the combinations though...like isn't the list of numbers such as in the picture in the E3-I23 cells what you mean by listing? What specifically are you looking for from the pictures you posted? Which cells? And the VBA editor software?

@crybloodwing 

 

It didn't work for me I must have done something wrong?

 

 

@crybloodwing 

 

Strangely, I receive the result like on the picture, not too sure what did I do wrong here?