I made a fairly easy function to count the number of employees scheduled during a certain hour on a certain day. The formula works, but it doesn't always calculate it. If I go back into the schedule, and re-enter the value in the cell, it then does re-calculate it. Is this a glitch or bad code on my part.
the function:
Function CountStaff(StartR As Range, StartTime As Range)
J = 0
Dim C As Object
For Each C In StartR
CurrentLine = CurrentLine + 1
If StartTime >= C And StartTime < C.Offset(0, 1) Then
If C.Interior.ColorIndex <> 43 Then
J = J + 1
End If
End If
Next
CountStaff = J
End Function
The Formula: =CountStaff(B$3:B$21,$R3)
The Range is the start times for all the employees on the schedule, $R3 holds the time being tested (say 9:00 am). The color check is if a cell is highlighted because of vacation time or another such event.