I named Sheet1!A1:T100 Segments. Sheet2!B1 named NumSegments and that cell has the formula =COUNT(Segments). Sheet2!B3 named PartSize with value 12.
Further in Sheet2,
A5: 1
B5: =LARGE(Segments,A5)
A6: =IF(A5<B$1,A5+1,#N/A)
B5 filled down into B6, A6:B6 filled down until formulas return #N/A. Then I defined the name SegmentList referring to the formula =Sheet2!$B$5:INDEX(Sheet2!$B$5:$B$1048576,NumSegments).
Then I came up with a simplistic 1-pass approach.
The logic here is to add the largest segments together with total length less than PartSize. This doesn't necessarily minimize total parts.
The keys to this approach are using segment sizes sorted in descending order and using a linked list (lnklst) to iterate through SegmentList, skipping over entries in the linked list as they're included with longer segments.
The result is entered into Sheet3 starting in cell A1. COUNT(A:A) is the total number of parts needed. The 1st column gives the number of segments or the error string too long for segment lengths longer than PartSize. The 2nd column is the total length of the segments, and the remaining columns are the segment lengths.
To repeat, this is simplistic, but it gives one approach for how to proceed.
Bookmarks