Excel:按顺序检查小时数,同一列,当条件为真时

Excel: check hours in sequential order, same column, when criteria is true

我有一个数据库,其中包含不同客户的发货订单,一次发货可以有多个预计到达时间不同的发货,逻辑是:每条路线上的发货必须遵循顺序(06:00-> 06:30->08:00) 而不是 (06:30->08:00->06:00) 所有时间都在同一列中,但路线编号在另一列中。必须仅对同一路线中的​​发货进行验证。

首先,我尝试使用单独的 sheet 单元格计算路线中每次与下一次之间的差异,但当公式遇到空白单元格时出现错误。公式为:

=IF(COUNTIFS($I:$I00;$I2;$A:$A00;$A)>1;$E3-$E2;0)

我使用 COUNTIFS() 来验证同一调度中心在同一路线上的调度 wan,因为 DB 合并了 5 个调度中心。该公式在检测到不正确的序列时返回负数,但它检测到相邻路线上最后一次和第一次调度之间的误报。

然后我尝试使用条件格式来检查这一点,使用:

=IF(COUNTIFS($I:$I00;I2;$A:$A00;A2)>1;E3<E2;0)

然而,有些不对... 如果有人可以给我一些见解来使这项工作有效,或者是否有另一种方法可以进行此验证(我确信有一种方法,但我还不知道),我将不胜感激。请帮忙。

UPDATE: Here is some sample data, as you can see the are times that are not sequential, but also false positives on last/first dispatches on each route

示例数据已澄清,显示了预期结果,需要避免误报。请帮忙

假设您有以下命名范围

  • Col_A 是您在 A 列中的数据;
  • Col_E 是您在 E 列中的数据;
  • Col_I 是您在第一列中的数据。

您可以使用以下公式作为格式规则:

=NOT(AGGREGATE(15,6,Col_E/(Col_A&Col_I=$A2&$I2),COUNTIFS($A:$A2,$A2,$I:$I2,$I2))=$E2)

突出显示 E 列,单元格 E2 是活动单元格,转到条件格式设置上面的格式规则,您应该有如下内容:

Column J 仅供演示。您的实际工作表中不需要此列。

The logic is to use Col_E/(Col_A&Col_I=$A2&$I2) to return the relevant range of time from Column E based on information in Column A and I, then use AGGREGATE function to return the nth smallest value from this range where nth is determined by the COUNTIFS formula, then compare the nth time with the actual time to find out if they are the same. If not that means a delivery was scheduled at a later time but positioned ahead of other deliveries that was scheduled at an earlier time, or vice versa (that's why both the ones that were delivered early with a later time and the ones that were delivered late with an earlier time are both highlighted in my example).

如果您有任何问题,请告诉我。干杯:)