저는 startDate로 지정된 시작 날짜와 endDate로 지정된 다른 셀을 가지고 있습니다. 셀을 클릭 할 때마다 캘린더가 튀어 나와 날짜를 입력합니다. 매크로가 endDate를 매월 마지막 날로 자동 변경하기를 원합니다. 따라서 사용자가 들어가서 시작 날짜를 입력하면 매크로는 그 달의 마지막 날인 종료 날짜를 입력합니다. 달력에 대한 코드도 여기에endDate를 월의 마지막 날로 설정하는 VBA를 만들어야합니다.
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
됩니다 :
=DATE(YEAR(startDate),MONTH(startDate)+1,0)
:
당신의 endDate가 세포에서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
매크로는 종료일을 입력합니다 * *? – ThunderFrame
나는 또한 공식이 더 적합하다고 생각합니다. '= EOMONTH (오늘, 0)' – L42