Created
July 18, 2011 06:53
-
-
Save bleis-tift/1088729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment