Excel VBA从日期对象获取月份 [英] Excel vba get month from Date object
本文介绍了Excel VBA从日期对象获取月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用日期值填充的单元格.然后将其存储在变量中.
Sub dateTest()
Dim min_date As Date
min_date = ThisWorkbook.Worksheets("setup").Cells(22, 5).value
MsgBox (min_date)
End Sub
但是,我希望与该对象分开获得一个月零一天.怎么做?
解决方案
Month()
和Day()
是您需要的功能:
MsgBox (Month(minDate))
MsgBox (Day(minDate))
另一种方法是使用Format函数:
MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")
I have a cell that gets filled with a date value. I then store it in a variable.
Sub dateTest()
Dim min_date As Date
min_date = ThisWorkbook.Worksheets("setup").Cells(22, 5).value
MsgBox (min_date)
End Sub
However, I would like to get a month and a day separately from that object. How to do it?
解决方案
Month()
and Day()
are the functions that you need:
MsgBox (Month(minDate))
MsgBox (Day(minDate))
Another way is to use the Format function:
MsgBox Format(minDate, "m")
MsgBox Format(minDate, "d")
这篇关于Excel VBA从日期对象获取月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文