Ive two dropdowns for selecting year and month. In month dropdown there is options JAN,FEB,MAR....DEC and ALL
. In Year 2016,2017,2018,2019,2020
I need a function which returns first day of that selection. If 2017 and All
selected, it should return 01/01/2017. If its 2017 and JUL
, the return value should be 01/07/2017
Also another function just opposite. If user gives 2018 and All
, it should return 31/12/2018. if user gives 2018 and FEB
, it should return 28/02/2018
So which is the best solution for this case..
What I tried for first day is as follows
Function firstDay(year As String, month As String) As Date
Dim fd As Date
If LCase(month) = "all" Then month = "JAN"
fd = DateValue("01 " & month & Space(1) & year)
firstDay = fd
End Function
But for last day I didn't get how to do that or the solution I tried was not great. So expecting a better solution in that (Of cource for firstday also if there is better option)