Here's what I get:
Row\Col |
A |
B |
C |
D |
E |
F |
G |
H |
I |
1 |
Item # |
Amount |
|
Item 1 |
Item 2 |
Item 3 |
Sum |
|
|
2 |
1 |
2377 |
|
1 |
20 |
23 |
4226 |
|
G2: =SUMPRODUCT(($A$2:$A$44 = D2:F2) * $B$2:$B$44) |
3 |
2 |
2229 |
|
2 |
18 |
19 |
4349 |
|
|
4 |
3 |
2174 |
|
3 |
16 |
17 |
4332 |
|
|
5 |
4 |
1832 |
|
4 |
13 |
15 |
4427 |
|
|
6 |
5 |
1748 |
|
5 |
12 |
14 |
4406 |
|
|
7 |
6 |
1716 |
|
6 |
10 |
11 |
4758 |
|
|
8 |
7 |
1695 |
|
7 |
8 |
9 |
4898 |
|
|
9 |
8 |
1625 |
|
|
|
|
0 |
|
|
10 |
9 |
1578 |
|
|
|
|
0 |
|
|
11 |
10 |
1523 |
|
|
|
|
0 |
|
|
12 |
11 |
1519 |
|
|
|
|
0 |
|
|
13 |
12 |
1477 |
|
|
|
|
0 |
|
|
14 |
13 |
1445 |
|
|
|
|
0 |
|
|
15 |
14 |
1181 |
|
|
|
|
0 |
|
|
16 |
15 |
1150 |
|
|
|
|
0 |
|
|
17 |
16 |
1082 |
|
|
|
|
0 |
|
|
18 |
17 |
1076 |
|
|
|
|
0 |
|
|
19 |
18 |
1070 |
|
|
|
|
0 |
|
|
20 |
19 |
1050 |
|
|
|
|
0 |
|
|
21 |
20 |
996 |
|
|
|
|
0 |
|
|
22 |
21 |
874 |
|
|
|
|
0 |
|
|
23 |
22 |
867 |
|
|
|
|
0 |
|
|
24 |
23 |
853 |
|
|
|
|
0 |
|
|
25 |
24 |
794 |
|
|
|
|
0 |
|
|
26 |
25 |
561 |
|
|
|
|
0 |
|
|
27 |
26 |
557 |
|
|
|
|
0 |
|
|
28 |
27 |
513 |
|
|
|
|
0 |
|
|
29 |
28 |
477 |
|
|
|
|
0 |
|
|
30 |
29 |
475 |
|
|
|
|
0 |
|
|
31 |
30 |
437 |
|
|
|
|
0 |
|
|
32 |
31 |
390 |
|
|
|
|
0 |
|
|
33 |
32 |
382 |
|
|
|
|
0 |
|
|
34 |
33 |
380 |
|
|
|
|
0 |
|
|
35 |
34 |
375 |
|
|
|
|
0 |
|
|
36 |
35 |
370 |
|
|
|
|
0 |
|
|
37 |
36 |
370 |
|
|
|
|
0 |
|
|
38 |
37 |
369 |
|
|
|
|
0 |
|
|
39 |
38 |
359 |
|
|
|
|
0 |
|
|
40 |
39 |
354 |
|
|
|
|
0 |
|
|
41 |
40 |
351 |
|
|
|
|
0 |
|
|
42 |
41 |
344 |
|
|
|
|
0 |
|
|
43 |
42 |
343 |
|
|
|
|
0 |
|
|
44 |
43 |
335 |
|
|
|
|
0 |
|
|
Sub TD()
Const dMin As Double = 4200#
Dim avdInp As Variant
Dim aviOut As Variant
Dim i As Long
Dim j As Long
Dim k As Long
Dim nInp As Long
Dim nOut As Long
With Range("B2", Cells(Rows.Count, "B").End(xlUp))
.Sort Key1:=.Cells(1), Order1:=xlDescending, Header:=xlNo
avdInp = .Value2
End With
nInp = UBound(avdInp, 1)
ReDim aviOut(1 To nInp \ 3, 1 To 3)
For i = 1 To nInp
For j = nInp - 1 To i + 1 Step -1
For k = nInp To j + 1 Step -1
If avdInp(i, 1) + avdInp(j, 1) + avdInp(k, 1) >= dMin Then
nOut = nOut + 1
aviOut(nOut, 1) = i
aviOut(nOut, 2) = j
aviOut(nOut, 3) = k
avdInp(j, 1) = -1E+300
avdInp(k, 1) = -1E+300
GoTo Nexti
End If
Next k
Next j
Nexti:
Next i
With Range("D2").Resize(nInp \ 3, 3)
.ClearContents
.Value = aviOut
End With
End Sub
Bookmarks