VBA判断两个单元格日期是否相同
可以使用以下代码来判断两个单元格日期是否相同:
Sub CompareDates()
Dim date1 As Date
Dim date2 As Date
date1 = Range("A1").Value
date2 = Range("B1").Value
If date1 = date2 Then
MsgBox "The dates are the same"
Else
MsgBox "The dates are different"
End If
End Sub
在上面的代码中,我们首先声明了两个变量 date1 和 date2 来存储两个单元格的日期值。我们使用 Range 函数来获取这些单元格中的值,这里假设这些日期值存储在单元格 A1 和 B1 中。
然后,我们使用 If 语句来比较这两个日期值。如果它们相同,我们会弹出一个消息框来显示它们相同。否则,我们会弹出另一个消息框来显示它们不同。
原文地址: http://www.cveoy.top/t/topic/fHW7 著作权归作者所有。请勿转载和采集!