Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public carry As Boolean
- Function AnsCount(range, trg)
- Dim res()
- res = EnumCombi(range, trg)
- AnsCount = UBound(res)
- End Function
- Function NextCells(range, crnt)
- Dim min
- Dim max
- min = range.Row
- max = range.Row + range.rows.Count - 1
- Dim results()
- ReDim results(UBound(crnt))
- For i = 1 To UBound(crnt)
- If carry Then
- If crnt(i).Row = max Then
- Set results(i) = range.Cells(min, crnt(i).Column)
- carry = True
- Else
- Set results(i) = range.Cells(crnt(i).Row + 1, crnt(i).Column)
- carry = False
- End If
- Else
- Set results(i) = crnt(i)
- carry = False
- End If
- Next i
- NextCells = results
- End Function
- Function Total(xs)
- Dim result
- result = 0
- For Each x In xs
- If IsEmpty(x) Then
- Else
- result = result + x.Value2
- End If
- Next x
- Total = result
- End Function
- Function EnumCombi(range, trg)
- Dim crnt()
- ReDim crnt(range.Columns.Count)
- For i = 1 To range.Columns.Count
- Set crnt(i) = range.Cells(range.Row, range.Column + i - 1)
- Next i
- Dim size
- size = 0
- Dim results()
- ReDim results(size)
- Do
- If Total(crnt) = trg Then
- ReDim Preserve results(size + 1)
- results(size) = crnt
- size = size + 1
- End If
- carry = True
- crnt = NextCells(range, crnt)
- Loop Until carry
- EnumCombi = results
- End Function
Add Comment
Please, Sign In to add comment