Excel VBA - 将单元格中的日期与当前日期进行比较 [英] Excel VBA - compare date in cell to current date
本文介绍了Excel VBA - 将单元格中的日期与当前日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(Excel 2010 VBA)
我有一个单元格(A1),其日期格式为mmm-yy(自定义类别)。
例如,如果我输入1/6/13,单元格显示6月13日。没关系。
在我的VB宏我需要检查这个日期是否是当前月份和年份是否是当前年份。我不在乎这一天。
解决方案
感谢Dave和MiVoth我做了:
Dim xdate As Date
xdate = Worksheets(sheet1)。范围(A1)
如果Month(Date)= Month (xdate)和Year(Date)= Year(xdate)then
MsgBoxOK
Else
MsgBoxnot OK
如果
这样做了!
非常感谢大家,
Gadi
(Excel 2010 VBA) I have a cell (A1) containing a date in the format of mmm-yy ("Custom" category). Foe example, if I enter 1/6/13 the cell shows June-13. That's fine. In my VB macro I need to check this date whether the month is the current month and whether the year is the current year. I don't care about the day.
解决方案
Thanks to Dave and MiVoth I did :
Dim xdate As Date
xdate = Worksheets("sheet1").Range("A1")
If Month(Date) = Month(xdate) And Year(Date) = Year(xdate) Then
MsgBox "OK"
Else
MsgBox "not OK"
End If
That did the job!
Thank a lot to everyone,
Gadi
这篇关于Excel VBA - 将单元格中的日期与当前日期进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文