Excel VBA - 将单元格中的日期与当前日期进行比较 [英] Excel VBA - compare date in cell to current date
本文介绍了Excel VBA - 将单元格中的日期与当前日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(Excel 2010 VBA)我有一个单元格 (A1),其中包含 mmm-yy 格式的日期(自定义"类别).例如,如果我输入 1/6/13,则单元格显示 June-13.没关系.在我的 VB 宏中,我需要检查该日期是否为当前月份以及年份是否为当前年份.我不在乎这一天.
(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.
推荐答案
感谢 Dave 和 MiVoth 我做到了:
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屋!
查看全文