Hi Petros,
You can use the function proposed there (in prevoius thread), but add a stage of collating entries first.
For instance, based on xladept approcach, but adding provisions for non-integer and for negative values:
Function CCHiLoX(R As Range, S As Range) As String
Dim P As String, P2 As Double, Q, T, i As Long, earlier As Long
Q = R
T = S
If Not IsNumeric(R(1, 1)) Then Q(1, 1) = 0
With Application.WorksheetFunction
For i = 2 To S.Rows.Count
If IsNumeric(R(i, 1)) Then
If .CountIf(S.Resize(i - 1, 1), S(i, 1)) > 0 Then
earlier = .Match(S(i, 1), S.Resize(i - 1, 1), 0)
Q(earlier, 1) = Q(earlier, 1) + Q(i, 1)
Q(i, 1) = 0
End If
Else
Q(i, 1) = 0
End If
Next i
End With
BubbleQ:
For i = LBound(Q) To UBound(Q) - 1
If Q(i, 1) < Q(i + 1, 1) Then
P2 = Q(i, 1)
Q(i, 1) = Q(i + 1, 1)
Q(i + 1, 1) = P2
P = T(i, 1)
T(i, 1) = T(i + 1, 1)
T(i + 1, 1) = P
GoTo BubbleQ
End If
Next i
For i = LBound(Q) To UBound(Q)
If Q(i, 1) <> 0 Then
CCHiLoX = CCHiLoX & "," & T(i, 1)
End If
Next i
CCHiLoX = Right(CCHiLoX, Len(CCHiLoX) - 1)
End Function
PS. Looks much longer, but it's not - Is written here without collapsing several instructions into 1 row with : separator.
Bookmarks