PDA

View Full Version : [SOLVED:] Grid combination logic problem



mdmackillop
04-07-2011, 07:34 AM
I'm looking to fill a grid with all combinations of selected data. The grid will be sized to suit that number. I've attached a workbook (macro free) to illustrate 2 scenarios. I'd welcome thoughts on whole or partial solutions, or even a logic I can code.

RonMcK
04-07-2011, 09:12 AM
MD,

So, is there a fixed number of bridged layers (you show 4 but tell us there are more) or do you want a solution that will look at a table (A7: D21 in your examples) and determine the number of instances of multiple options? (edited in note: I'll try to be smarter than the emoticons, they're parsing data in the middle of terms, such as XL Ranges. Arrggghh! )

In your Check area above the new table, you test the totals for the column and those to its left, counting the number of instances of this column's total. In all your cases, each total is unique. What happens if two are identical? Seems possible that it will happen even though you have unique data sets in each column. Just a thought.

The second check, summing the powers of 2 numbers for the bridged layers should always yield a unique number.

Thanks, I'll keep pondering this critter,

Cheers,

mdmackillop
04-08-2011, 01:03 AM
Turned out simpler than i thought (for this bit anyway). Now I just need to make it dynamic.

Sub Grps()
Dim arr1, a
Dim arr2, b
Dim arr3, c
Dim arr4, d
Dim col As New Collection
arr1 = Array(26, 27)
arr2 = Array(29, 30)
arr3 = Array(33, 34, 35)
arr4 = Array(37, 38)
For Each a In arr1
For Each b In arr2
For Each c In arr3
For Each d In arr4
i = i + 1
Cells(a, 15 + i).FormulaR1C1 = "=RC8"
Cells(b, 15 + i).FormulaR1C1 = "=RC8"
Cells(c, 15 + i).FormulaR1C1 = "=RC8"
Cells(d, 15 + i).FormulaR1C1 = "=RC8"
Next
Next
Next
Next
End Sub

RonMcK
04-08-2011, 12:07 PM
And, this code picks up the values for the non-bridged variables:

Sub Grp2()
Dim arr0, e
Dim col As New Collection
arr0 = Array(24, 25, 28, 31, 32, 36, 39, 40)
Do While i <= 24
For Each e In arr0
Cells(e, 15 + i).FormulaR1C1 = "=RC8"
Next
i = i + 1
Loop
End Sub