VBA中的时间操作 [英] Time operation in VBA
本文介绍了VBA中的时间操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要做的,我意识到它没有用.
Here's what I want to do and I realized it wasn't working.
If Time > 23 And Time < 7 Then
ws.Cells(Target.Row, 12).Value = 3
ElseIf Time > 7 And Time < 15 Then
ws.Cells(Target.Row, 12).Value = 1
Else
ws.Cells(Target.Row, 12).Value = 2
End If
我想用这些东西做什么...如果实际时间超过11 PM但不到7 AM ...它在一个单元格中写入3 ...依此类推...问题是我意识到此比较时间> 23或时间<7不起作用...如何将时间"功能与实际小时数进行比较?谢谢!
What I want to do with this stuff... if the actual time is over 11 PM but less than 7 am... it writes 3 in a cell... and so on... The problem is that I realized that this comporison Time > 23 or Time < 7 doesn't work... how can I compare Time function with the actual hour? Thanks!
推荐答案
尝试一下
If Hour(now) > 23 or Hour(now) <= 7 Then
ws.Cells(Target.Row, 12).Value = 3
ElseIf Hour(now) > 7 And Hour(now) < 15 Then
ws.Cells(Target.Row, 12).Value = 1
Else
ws.Cells(Target.Row, 12).Value = 2
End If
这篇关于VBA中的时间操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文