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: 19

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,215,926
Messages
6,127,731
Members
449,401
Latest member
TTXS

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