Option
Explicit
Sub
Summanden_ermitteln()
Dim
kk
As
Long
, zz
As
Long
, erg
As
String
, ergT
As
String
Dim
Atst
As
Double
, Amax
As
Double
Dim
anzZ
As
Long
, ii
As
Long
, umsch
As
Boolean
, arrB()
As
Boolean
anzZ = Cells(Rows.Count, 1).
End
(xlUp).Row - 1
ReDim
arrB(1
To
anzZ)
zz = 1
Columns(
"C:D"
).ClearContents
[C1:D1] = Split(
"Treffer Summanden"
)
For
ii = 1
To
2 ^ anzZ - 1
Atst = 0
erg =
""
umsch =
True
For
kk = anzZ
To
1
Step
-1
If
umsch
Then
arrB(kk) =
Not
arrB(kk)
If
arrB(kk)
Then
umsch =
False
End
If
Atst = Atst - arrB(kk) * Cells(kk + 1, 1)
If
Atst > Cells(2, 2)
Then
Exit
For
erg = IIf(arrB(kk),
"1"
,
"0"
) & erg
Next
kk
If
Atst <= Cells(2, 2)
And
Atst >= Amax
Then
If
Atst > Amax
Then
Amax = Atst
If
Amax = Cells(2, 2)
Then
zz = zz + 1
Cells(zz, 3) = erg
ergT =
""
For
kk = 1
To
anzZ
If
arrB(kk)
Then
ergT = ergT & Cells(kk + 1, 1) &
" + "
Next
kk
Cells(zz, 4) = Left(ergT, Len(ergT) - 3)
End
If
End
If
Next
ii
Cells(2, 2).
Select
End
Sub