Hello,
I have this VBA (below) which will allow the summing of a list of numbers to reach a stated number.
When using =getcombination(A2:A9,C2) for example, where A2:A9 is a list of numbers, and C2 is the desired sum
However, the result is only 1 possible combination (and usually not a desired one). Is there a way to modify the VBA so the 1 combination shown is the result with the fewest number of combinations?
Code
Function GetCombination(CoinsRange As Range, SumCellId As Double) As String
'updateby Extendoffice
Dim xStr As String
Dim xSum As Double
Dim xCell As Range
xSum = SumCellId
For Each xCell In CoinsRange
If Not (xSum / xCell < 1) Then
xStr = xStr & Int(xSum / xCell) & " of " & xCell & " "
xSum = xSum - (Int(xSum / xCell)) * xCell
End If
Next
GetCombination = xStr
End Function
Display More