I am trying to count the number of people scheduled for each hour of the day. I have the formula below that works but when the shift starts with a time that is PM and ends with a time that is AM it will not count accurately. I often have shifts that start at 8pm and end at 2am. The formula below will not calculate properly in this instance.

Any help wtih this would be greatly appreciated.

=SUMPRODUCT(($B$29>=$D$5:$D$18)*($B$29<$E$5:$E$18))