I have 2 cells that one is starting date assigned as startDate and another cell assigned endDate. Everytime I click on the cell a calendar pops out and I enter the date. I want the macro to change the endDate to the last day of the month automatically. So when the user goes in and enters a start date the macro will input the end date which is the last day of that month. Here is the code I have right now:
Function dhLastDayInMonth(Optional endDate As Date = 0) As Date
' Return the last day in the specified month.
If endDate = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Date
End If
dhLastDayInMonth = DateSerial(Year(endDate), _
Month(dtmDate) + 1, 0)
End Function
also Here is the code for the calendar:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'check cells for desired format to trigger the calendarfrm.show routine
'otherwise exit the sub
Dim DateFormats, DF
DateFormats = Array("m/d/yy;@", "mmmm d yyyy")
For Each DF In DateFormats
If DF = Target.NumberFormat Then
If CalendarFrm.HelpLabel.Caption <> "" Then
CalendarFrm.Height = 191 + CalendarFrm.HelpLabel.Height
Else: CalendarFrm.Height = 191
CalendarFrm.Show
End If
End If
Next
End Sub
=EOMONTH(TODAY(),0)
– L42