Solverを使えば完全ではなくても実用的なものができると思います。
異なる長さのものを組み合わせて、12000になればいいので、そのようにVBAでプログラムします。
結果を見て、左右対称を考えるか、はじめに材料の数を2分して計算すればいいでしょう。
A列に寸法、B列に個数を入れて、下記プログラムを実行すれば、C列以下に結果が出ます。
それを見て気に入るように積めばいいでしょう。
Sub solver3()
Dim r1 As Integer, r2 As Integer, c As Integer, n As Integer, lmax As Single
Dim rm As Integer, nrm As Integer, total As Single
r1 = 2
r2 = Cells(r1, 1).End(xlDown).Row
c = 3
n = 0
lmax = 12000
Range(Cells(r1, c - 2), Cells(r2, c - 1)).Sort Key1:=Cells(r1, c - 2), Order1:=xlDescending, _
Key2:=Cells(r1, c - 1), Order2:=xlDescending
Range(Cells(r1, c + 2), Cells(r2 + 1, 256)).ClearContents
Cells(r2 + 1, c - 1).FormulaR1C1 = "=SUM(R[" & -(r2 - 1) & "]C:R[-1]C)"
total = Cells(r2 + 1, c - 1)
SolverReset
While total > 0
Range(Cells(r1, c + 1), Cells(r2, c + 1)).FormulaR1C1 = "=RC1*RC[-1]"
Range(Cells(r1, c), Cells(r2, c)) = 1
Range(Cells(r2 + 1, c - 1), Cells(r2 + 1, c + 1)).FormulaR1C1 = "=SUM(R[" & -(r2 - 1) & "]C:R[-1]C)"
rm = r1
nrm = Cells(rm, c - 1)
While nrm = 0
rm = rm + 1
nrm = Cells(rm, c - 1)
Wend
SolverAdd CellRef:=Cells(rm, c), Relation:=3, FormulaText:="1"
SolverOk SetCell:=Cells(r2 + 1, c + 1), MaxMinVal:=1, ValueOf:=lmax, ByChange:=Range(Cells(r1, c), Cells(r2, c))
SolverAdd CellRef:=Range(Cells(r1, c), Cells(r2, c)), Relation:=1, FormulaText:=Range(Cells(r1, c - 1), Cells(r2, c - 1))
SolverAdd CellRef:=Range(Cells(r1, c), Cells(r2, c)), Relation:=3, FormulaText:="0"
SolverAdd CellRef:=Range(Cells(r1, c), Cells(r2, c)), Relation:=4, FormulaText:="整数"
SolverAdd CellRef:=Cells(r2 + 1, c + 1), Relation:=1, FormulaText:=Format(lmax)
SolverSolve userfinish:=True
Range(Cells(r2 + 1, c - 1), Cells(r2 + 1, c + 1)).Copy
c = c + 3
Cells(r2 + 1, c - 1).PasteSpecial
Range(Cells(r1, c - 1), Cells(r2, c - 1)).FormulaR1C1 = "=RC[-3]-RC[-2]"
total = Cells(r2 + 1, c - 1)
SolverReset
n = n + 1
Columns(n * 3 + 2).EntireColumn.Hidden = True
Wend
Cells(r2 + 1, c) = n
End Sub
お礼
ありがとうございます!! VBAは自動記録のコードを触るぐらいしかしたことがないのですが、 がんばってみます、 残念ながらコンパイルエラーが表示されてしまい SolverReset SUBまたは fanctinon が定義されてません。。 という感じででるのです、 少し自分で調べてみます ありがとうございます。