问题
IF(AND(H$2>=$B2,H$2<=$C2),"X","")
Works for 08:30-15:30 and 9:30-18:30, but it does for shift 19:30-4:30 check the image (highlighted in yellow cell)

回答1:
A "simple" solution would be to check if start
is bigger than end
. In that case, you will need to check for
time >= start OR time <= end
Something like :
=IF(
$B2<$C2;
IF(AND(H$2>=$B2;H$2<=$C2);"X";"");
IF(OR( H$2>=$B2;H$2<=$C2);"X";"")
)
回答2:
Better to include date part into your formula of each cell showing time and re-format these cells to show the time part only. They include:
1. Start and end for each resource: For example, for B3
, make it as "2018-07-02 08:30
" and format it as "hh:mm
";
2. Time marker in the header in the second row, i.e. for D2
, E2
, ..., sets up D2
as the starting point to include the date part as well, then sets cells after it increase 30 minuets from each previous cell. That is, sets E2
as =D2+TIME(0,30,0)
, and copy E2
right. Also re-format all these cells as "hh:mm";
3. Date marker in the header in first row, i.e. for D1
, AM1
, ..., let D1
as =D2
and format as date (and merge cells of course) , then copy right.
In this way, the formula should work and the cells' format looks same.
来源:https://stackoverflow.com/questions/51238467/if-formula-on-time-cell-not-working