如何检查Excel中的日期单元格是否为空? [英] How to check if a date cell in Excel is empty?
本文介绍了如何检查Excel中的日期单元格是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果觉得这样很简单,但是我不会让它工作,而不再检索单元格的值。
首先,我有2个日期单元格:
Dim agreeDate As Date
/ pre>
Dim completedDate As Date
这个工作..(但看起来很乱)
agreeDate = Worksheets(Data)。Cells(Counter,7).Value
completedDate = Worksheets(Data)。Cells(Counter,9).Value
If(IsEmpty工作表(Data)。Cells(Counter,7).Value)= True)Or(IsEmpty(Worksheets(Data)。Cells(Counter,9).Value)= True)然后
[..做东西]
结束如果
这不工作 - 为什么不? !
agreeDate = Worksheets(Data)。Cells(Counter,7).Value
completedDate = Worksheets(数据)。单元格(Counter,9).Value
If(IsEmpty(agreeDate)= True)或IsEmpty(completedDate)= True)然后
[.. do东西]
如果
有没有办法将if语句写在干净的
解决方案由于只有Variant类型的变量可以为空,因此您需要对Date类型进行不同的测试。 >
检查零:
如果agreeDate = 0或completedDate = 0 Then
但是更安全的路径是将变量更改为Variant类型,然后执行此测试:
如果IsDate(agreeDate)= False或IsDate(completedDate)= False然后
If feels like this should be really easy but I dont get it to work without retrieving the value of the cell again.
To start with, I have 2 date cells:
Dim agreedDate As Date Dim completedDate As Date
THIS WORKS .. (but looks messy)
agreedDate = Worksheets("Data").Cells(Counter, 7).Value completedDate = Worksheets("Data").Cells(Counter, 9).Value If (IsEmpty(Worksheets("Data").Cells(Counter, 7).Value) = True) Or (IsEmpty(Worksheets("Data").Cells(Counter, 9).Value) = True) Then [.. do stuff] End If
THIS DOES NOT WORK - WHY NOT?!
agreedDate = Worksheets("Data").Cells(Counter, 7).Value completedDate = Worksheets("Data").Cells(Counter, 9).Value If (IsEmpty(agreedDate) = True) Or IsEmpty(completedDate) = True) Then [.. do stuff] End If
Is there a way to write the if statement in a clean and easy way?
解决方案Since only variables of type Variant can be Empty, you need a different test for Date types.
Check for zero:
If agreedDate = 0 Or completedDate = 0 Then
But a safer path would be to change the variables to type Variant and then do this test:
If IsDate(agreedDate) = False Or IsDate(completedDate) = False Then
这篇关于如何检查Excel中的日期单元格是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文