View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default group (add) numbers without exceeding 168

On the assumption there are no other rules except not exceeding 168 then try
this

Sub lime()
For x = 1 To Cells(Rows.Count, "A").End(xlUp).Row
grandtotal = grandtotal + Cells(x, 1).Value
nextvalue = Cells(x, 1).Value
If total + nextvalue <= 168 Then
total = total + nextvalue
Else
Sum = Sum + total
total = nextvalue
Count = Count + 1
End If
Next
If Sum < grandtotal Then Count = Count + 1
MsgBox Count & " Groups of 168 or less"
End Sub

Mike

"Zab" wrote:

hello i am triing to group these numbers below, but i do not want the total
to exceed 168. i need to know how many pieces that are 168 in length it will
take. i would imagine it will take some vba to conduct this and i am fine
with this.

23.5
23.5
30.883
30.883
30.883
30.883
37.383
37.383
43.411
43.411
47
48
49.876
50.646
50.883
50.883
50.883
50.883
50.883
50.883
50.883
50.883
55.383
55.383
59.5
90


below i have manually grouped the numbers together with their totals to the
right.
50.883 50.883 50.883 = 152.649
50.883 50.883 50.883 = 152.649
48 43.411 30.883 30.883 = 153.177
55.383 50.883 50.883 = 157.149
50.646 47 43.411 23.5 = 164.557
59.5 55.383 49.876 = 164.759
90 37.383 37.383 = 164.766

30.883 30.883 23.5 = 85.266

--
Thank You in advance, Zab