Hello everyone, I've been figuring out VB code to set out time schedule for each date.

Here is my raw table.

[TABLE="width: 500"]

<tbody>[TR]

[TD]No[/TD]

[TD]Qty[/TD]

[TD]Date[/TD]

[TD]Time[/TD]

[/TR]

[TR]

[TD]1[/TD]

[TD]2[/TD]

[TD]18/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]2[/TD]

[TD]212[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]3[/TD]

[TD]211[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]4[/TD]

[TD]294[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]5[/TD]

[TD]463[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]6[/TD]

[TD]253[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]7[/TD]

[TD]21[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]8[/TD]

[TD]250[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]9[/TD]

[TD]11[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]10[/TD]

[TD]88[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]11[/TD]

[TD]2[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]12[/TD]

[TD]945[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]13[/TD]

[TD]790[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]14[/TD]

[TD]121[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

</tbody>[/TABLE]

and what I expect the table will shown after running the macro code is like this.

[TABLE="width: 500"]

<tbody>[TR]

[TD]No[/TD]

[TD]Qty[/TD]

[TD]Date[/TD]

[TD]Time[/TD]

[/TR]

[TR]

[TD]1[/TD]

[TD]2[/TD]

[TD]18/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]2[/TD]

[TD]212[/TD]

[TD]19/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]3[/TD]

[TD]211[/TD]

[TD]19/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]4[/TD]

[TD]294[/TD]

[TD]19/8/2014[/TD]

[TD]2:00[/TD]

[/TR]

[TR]

[TD]5[/TD]

[TD]463[/TD]

[TD]19/8/2014[/TD]

[TD]3:00[/TD]

[/TR]

[TR]

[TD]6[/TD]

[TD]253[/TD]

[TD]19/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

[TR]

[TD]7[/TD]

[TD]21[/TD]

[TD]19/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

[TR]

[TD]8[/TD]

[TD]250[/TD]

[TD]19/8/2014[/TD]

[TD]5:00[/TD]

[/TR]

[TR]

[TD]9[/TD]

[TD]11[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]10[/TD]

[TD]88[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]11[/TD]

[TD]2[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]12[/TD]

[TD]945[/TD]

[TD]20/8/2014[/TD]

[TD]2:00[/TD]

[/TR]

[TR]

[TD]13[/TD]

[TD]790[/TD]

[TD]20/8/2014[/TD]

[TD]3:00[/TD]

[/TR]

[TR]

[TD]14[/TD]

[TD]121[/TD]

[TD]20/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

</tbody>[/TABLE]

so there is several several criteria to decide the time:

1. if the date is different then the time will start again from 1:00

2. if the quantity is more than 500 it will add an hour to fill the time.

i hope my explanation is clear and really looking forward for your help as I've been trying to find the code for days.

Here is the code i've been trying but it keeps on showing the wrong time.

Thank you

Here is my raw table.

[TABLE="width: 500"]

<tbody>[TR]

[TD]No[/TD]

[TD]Qty[/TD]

[TD]Date[/TD]

[TD]Time[/TD]

[/TR]

[TR]

[TD]1[/TD]

[TD]2[/TD]

[TD]18/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]2[/TD]

[TD]212[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]3[/TD]

[TD]211[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]4[/TD]

[TD]294[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]5[/TD]

[TD]463[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]6[/TD]

[TD]253[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]7[/TD]

[TD]21[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]8[/TD]

[TD]250[/TD]

[TD]19/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]9[/TD]

[TD]11[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]10[/TD]

[TD]88[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]11[/TD]

[TD]2[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]12[/TD]

[TD]945[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]13[/TD]

[TD]790[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

[TR]

[TD]14[/TD]

[TD]121[/TD]

[TD]20/8/2014[/TD]

[TD][/TD]

[/TR]

</tbody>[/TABLE]

and what I expect the table will shown after running the macro code is like this.

[TABLE="width: 500"]

<tbody>[TR]

[TD]No[/TD]

[TD]Qty[/TD]

[TD]Date[/TD]

[TD]Time[/TD]

[/TR]

[TR]

[TD]1[/TD]

[TD]2[/TD]

[TD]18/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]2[/TD]

[TD]212[/TD]

[TD]19/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]3[/TD]

[TD]211[/TD]

[TD]19/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]4[/TD]

[TD]294[/TD]

[TD]19/8/2014[/TD]

[TD]2:00[/TD]

[/TR]

[TR]

[TD]5[/TD]

[TD]463[/TD]

[TD]19/8/2014[/TD]

[TD]3:00[/TD]

[/TR]

[TR]

[TD]6[/TD]

[TD]253[/TD]

[TD]19/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

[TR]

[TD]7[/TD]

[TD]21[/TD]

[TD]19/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

[TR]

[TD]8[/TD]

[TD]250[/TD]

[TD]19/8/2014[/TD]

[TD]5:00[/TD]

[/TR]

[TR]

[TD]9[/TD]

[TD]11[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]10[/TD]

[TD]88[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]11[/TD]

[TD]2[/TD]

[TD]20/8/2014[/TD]

[TD]1:00[/TD]

[/TR]

[TR]

[TD]12[/TD]

[TD]945[/TD]

[TD]20/8/2014[/TD]

[TD]2:00[/TD]

[/TR]

[TR]

[TD]13[/TD]

[TD]790[/TD]

[TD]20/8/2014[/TD]

[TD]3:00[/TD]

[/TR]

[TR]

[TD]14[/TD]

[TD]121[/TD]

[TD]20/8/2014[/TD]

[TD]4:00[/TD]

[/TR]

</tbody>[/TABLE]

so there is several several criteria to decide the time:

1. if the date is different then the time will start again from 1:00

2. if the quantity is more than 500 it will add an hour to fill the time.

i hope my explanation is clear and really looking forward for your help as I've been trying to find the code for days.

Here is the code i've been trying but it keeps on showing the wrong time.

Code:

```
Sub try()Dim i, j, k As Integer
Dim cum As Integer
rowz = Range("B6").End(xlDown).Row
Cells(7, 17).Value = ("1")
For i = 7 To rowz - 1
cum = Cells(i, 10)
k = 1
If Range("P" & i) <> Range("P" & i + 1) Then
Cells(i + 1, 17).Value = ("1")
Else
cum = cum + Cells(i + 1, 10)
'k = k + 1
j = 1
Do While cum < 500
Cells(i + j, 17) = k
i = i + 1
cum = cum + Cells(i + j, 10)
j = j + 1
Loop
k = k + 1
End If
Next i
End Sub
```

Thank you

Last edited: