VBA Run Macro Last Day of the Month

2019-09-17 21:45发布

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?

EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)

1条回答
再贱就再见
2楼-- · 2019-09-17 22:13

The function WorksheetFunction.EoMonth returns a Date, while you want a numeric value representing the Day (of the last day of the month).

So you need a Long variable, and you can use the Day function.

EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)

Dim myDay As Long
myDay = Day(EndDate)
查看更多
登录 后发表回答