Hi, and welcome to the forum.
Does the following macro (also attached) help?
Sub MoveMarbles()
Dim lJars As Long, arJars() As Variant, st As String, st2 As String, lOrig As Long
Dim lTotal As Long, lAverage As Long, x As Long, y As Long, lPot As Long
arJars = Sheet1.Range("A1").CurrentRegion
lJars = UBound(arJars)
For x = 1 To lJars
lTotal = lTotal + arJars(x, 1)
Next x
lAverage = lTotal / lJars
For x = lJars To 1 Step -1
If arJars(x, 1) > lAverage Then
lOrig = arJars(x, 1)
lPot = lPot + arJars(x, 1) - lAverage
st = st & " Take " & arJars(x, 1) - lAverage & " marbles from the pot with " & lOrig & " marbles,"
arJars(x, 1) = lAverage
Else
lOrig = arJars(x, 1)
lPot = lPot - arJars(x, 1)
st2 = st2 & " put " & lAverage - arJars(x, 1) & " in the pot with " & lOrig & " marbles,"
arJars(x, 1) = lAverage
End If
Next x
Range("c1") = st & " " & st2
End Sub
Bookmarks