Combine based on certain criteria

yasawa

New Member
Joined
Dec 29, 2011
Messages
21
Hello
I found this example (function) that makes all possible combinations of different ingredients, I want to add a condition that every ingredient can only be used in certain position ( column)...
Any help would be much appreciated
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    188 KB · Views: 24

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
And here is the code I'm using (thanks to the one who wrote it)
Excel Formula:
Public result() As Variant


Function Combinations(rng As Range, n As Single)
rng1 = rng.Value

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

ReDim Preserve result(UBound(result, 1), UBound(result, 2) - 1)
Combinations = Application.Transpose(result)

End Function

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

For f = d To UBound(r, 1)

    result(e, UBound(result, 2)) = r(f, 1)

    If e = (c - 1) Then

        ReDim Preserve result(UBound(result, 1), UBound(result, 2) + 1)
        
        For g = 0 To UBound(result, 1)
            result(g, UBound(result, 2)) = result(g, UBound(result, 2) - 1)
        Next g
    Else
        Call Recursive(r, c, f + 1, e + 1)
    End If
    
Next f
    
End Function
 
Upvote 0
I'll try to make a macro that deletes rows based on the needed criteria, any other work around idea is apreciated
Thanks
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,522
Members
453,050
Latest member
Obil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top