I'm trying to create a sheet with some intervals in each row. The total of sums of the intervals of each row must be 08:00. But I'm having problems, because the excel doesn't calculate each row at time, but every row simultaneously, and the total in each row ends in a value different of 08:00.
Here my source:
Here my file:
Month.xlsm
Here my source:
VBA Code:
Sub Macro1()
Range("C2:G32").Select
Selection.ClearContents
For Each linha In Range("A2:A32")
i = linha.Row
If Range("B" & i) = "Saturday" Then
Range("C" & i).Value = " "
Range("D" & i).Value = " "
Range("E" & i).Value = " "
Range("F" & i).Value = " "
Range("G" & i).Value = " "
ElseIf Range("B" & i) = "Sunday" Then
Range("C" & i).Value = " "
Range("D" & i).Value = " "
Range("E" & i).Value = " "
Range("F" & i).Value = " "
Range("G" & i).Value = " "
Else
While (Range("G" & i) <> "08:00")
Range("C" & i).Value = "=TEXT(RAND()*(TIME(8,16,0)-TIME(7,45,0))+TIME(7,45,0),""HH:MM"")"
Range("D" & i).Value = "=TEXT(RAND()*(TIME(12,16,0)-TIME(11,45,0))+TIME(11,45,0),""HH:MM"")"
Range("E" & i).Value = "=TEXT(RAND()*(TIME(13,46,0)-TIME(13,15,0))+TIME(13,15,0),""HH:MM"")"
Range("F" & i).Value = "=TEXT(RAND()*(TIME(17,46,0)-TIME(17,15,0))+TIME(17,15,0),""HH:MM"")"
Range("G" & i).Value = "=TEXT((D" & i & " - C" & i & ") + (F" & i & " - E" & i & "),""HH:MM"")"
Wend
End If
Next
End Sub
Here my file:
Month.xlsm