I want to return the last day in the month. The month is selected from a drop-down combo box. If I select January, this will return "1/31/2017" but I just want it to return 31. What am I missing?
我想在这个月的最后一天回来。从下拉组合框中选择月份。如果我选择1月份,这将返回“2017年1月31日”,但我只是想让它返回31.我错过了什么?
EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)
1 个解决方案
#1
3
The function WorksheetFunction.EoMonth
returns a Date
, while you want a numeric value representing the Day (of the last day of the month).
函数WorksheetFunction.EoMonth返回一个Date,而您想要一个表示Day(该月的最后一天)的数值。
So you need a Long
variable, and you can use the Day
function.
所以你需要一个Long变量,你可以使用Day函数。
EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)
Dim myDay As Long
myDay = Day(EndDate)
#1
3
The function WorksheetFunction.EoMonth
returns a Date
, while you want a numeric value representing the Day (of the last day of the month).
函数WorksheetFunction.EoMonth返回一个Date,而您想要一个表示Day(该月的最后一天)的数值。
So you need a Long
variable, and you can use the Day
function.
所以你需要一个Long变量,你可以使用Day函数。
EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)
Dim myDay As Long
myDay = Day(EndDate)