View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
merjet merjet is offline
external usenet poster
 
Posts: 812
Default Function that groups together Overtime hours by 7.5 hrs

The Sub below should get you started. Run it more than once for more
than one vacation day. Nor will it grab OT if there are more than, but
not exactly equal, 7.5 hours available. In other words, it won't split
days. Frankly, if you are going to split days, you may as well not
skip days either. In other words, in your example split line 4 rather
than using line 5. If you still want to split days, you can modify the
Sub below.

Hth,
Merjet

Sub GatherOT()
Dim iRow As Integer
Dim iRow2 As Integer
Dim iPos As Integer
Dim dtDay As Date
Dim aRows As String
Dim sSum As Single

Do
iRow = iRow + 1
If Cells(iRow, 4) = "" Then
If sSum + Cells(iRow, 3) <= 7.5 Then
sSum = sSum + Cells(iRow, 3)
aRows = aRows & "x" & iRow
End If
End If
If sSum = 7.5 Then
dtDay = InputBox("Enter vacation day (mm/dd).")
Do
aRows = Right(aRows, Len(aRows) - 1)
iPos = InStr(aRows, "x")
If iPos = 0 Then
iRow2 = aRows
aRows = ""
Else
iRow2 = Left(aRows, iPos - 1)
aRows = Right(aRows, Len(aRows) - iPos + 1)
End If
Cells(iRow2, 4) = dtDay
Loop Until aRows = ""
Exit Sub
End If
Loop Until Cells(iRow + 1, 1) = ""
End Sub