我在Excel中有3张
工作表1包含24小时格式的到达时间列
到达时间
11:00
22:00
05:00
09:00
工作表2包含24小时格式的出发时间列
出发时间
14:00
23:00
18:00
10:00
工作表3包含24小时格式的计划时间列
计划时间
15:00
18:00
3:00 - 12:00
12:00 - 16:00
现在我想要一个公式,如果计划时间在到达时间和时间之间。出发时间然后将列DELIVERY更新为YES否则NO。
但不幸的是,我的计划时间栏包含时间范围(3:00-12:00)和&固定时间(3:00)。
那么如何编写通用公式来更新DELIVERY列?因为我的计划时间栏包含时间范围和时间范围。固定时间。
答案 0 :(得分:0)
我确信它可以以更整洁的方式完成(你可以将其中一些组合成更大的公式)但我已经得到了以下内容。
没有经过详尽的测试,但我认为它可以满足需要。
理论是要弄清楚你有什么样的输入,然后相应地处理它,我认为你有时钟类型和范围变量。
因此,前两个“帮助”列是时钟类型(B2):
=IF(RIGHT(A2,1)="M","12","24")
然后是范围(C2):
`= NOT(ISERROR(FIND( “ - ”,A2)))'
然后我有四列来计算12小时和24小时时钟范围的开始和结束(对不起,但这些很长!),D2是:
=IF(MOD(IF(RIGHT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2))+0.5)*2,1)=0,IF(RIGHT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2))+0.5)-0.5,IF(RIGHT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"),LEN(SUBSTITUTE(LEFT(A2,FIND("-",A2)-2),".",":"))-2))+0.5))
E2是:
=IF(MOD(IF(RIGHT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2))+0.5)*2,1)=0,IF(RIGHT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2))+0.5)-0.5,IF(RIGHT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),2)="AM",VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2)),VALUE(LEFT(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"),LEN(SUBSTITUTE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2),".",":"))-2))+0.5))
F2是:
=VALUE(LEFT(A2,FIND("-",A2)-2))
G2是:
=VALUE(MID(A2,FIND("-",A2)+2,LEN(A2)-FIND("-",A2)+2))
如果您仍然清醒,我们会在类型达到您的标准时继续努力。 H2(24小时而不是范围)是:
=AND(A2>=Sheet1!A2,A2<=Sheet2!A2)
I2(12小时而不是范围)是:
=AND(IF(RIGHT(A2,2)="AM",VALUE(LEFT(A2,LEN(A2)-2)),VALUE(LEFT(A2,LEN(A2)-2))+12)>=Sheet1!A2,IF(RIGHT(A2,2)="AM",VALUE(LEFT(A2,LEN(A2)-2)),VALUE(LEFT(A2,LEN(A2)-2))+12)<=Sheet2!A2)
J2(24小时且是范围)是:
=OR(AND(F2>=Sheet1!A2,F2<=Sheet2!A2),AND(G2>=Sheet1!A2,G2<=Sheet2!A2))
K2(12小时且是范围)是:
=OR(AND(D2>=Sheet1!A2,D2<=Sheet2!A2),AND(E2>=Sheet1!A2,E2<=Sheet2!A2))
现在我们来到您的Delivery列,我已经使用TRUE / FALSE而不是“Yes”/“No”,这只是使用上面的类型和结果,以便使用正确的类型和结果正确的方案:
=IF(B2=24,IF(C2,J2,H2),IF(C2,K2,I2))
正如我所说,没有经过测试,但希望如果我犯了错误(这很可能),你应该能够采取逻辑,然后进行必要的调整。