' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Sub combisplit2(maxlen As Integer, lens As Variant, n() As Integer, curlen As Integer, start As Integer)
    Dim i As Integer
    Dim s As String
    If lens(0) > maxlen - curlen Then
        s = ""
        For i = 0 To UBound(lens)
            s = s & " " & n(i)
        Next
        MsgBox s
    Else
        i = start
        While i <= UBound(lens)
            If lens(i) <= maxlen - curlen Then
                n(i) = n(i) + 1
                Call combisplit2(maxlen, lens, n, curlen + lens(i), i)
                n(i) = n(i) - 1
            End If
            i = i + 1
        Wend
    End If
End Sub

Sub combisplit(maxlen As Integer, lens As Variant)
    Dim n() As Integer
    ReDim n(UBound(lens))
    Call combisplit2(maxlen, lens, n, 0, 0)
End Sub

Sub test_combisplit()
    Call combisplit(300, Array(40, 80, 110, 130, 150, 180, 210))
End Sub
