' [139.xls] ' [Module1] のコード '★★☆ うるう年を判定して月末日を取得する ☆★★ Option Explicit Sub start() UserForm1.Show End Sub ' [UserForm1] のコード Option Explicit Private Sub ScrollBar1_Change() 'スクロールバーで指定した年度で、3月1日の前日が29日かどうかを判定します 'DateSerial関数の引数の 0 は1日の前日を意味します With ScrollBar1 If Day(DateSerial(.Value, 3, 0)) = 29 Then Label1.Caption = .Value & "年は閏年です" Else Label1.Caption = .Value & "年は平年です" End If End With 'ScrollBar1 の変更結果を ScrollBar2 に伝える ScrollBar2_Change End Sub Private Sub ScrollBar1_Scroll() ScrollBar1_Change End Sub Private Sub ScrollBar2_Change() '月末日を取得する関数の使い方 'Day(DateSerial(指定年度, 指定月 + 1, 0)) Label3.Caption = ScrollBar1.Value & "年の" & _ ScrollBar2.Value & "月末日は" & _ Day(DateSerial(ScrollBar1.Value, ScrollBar2.Value + 1, 0)) End Sub Private Sub ScrollBar2_Scroll() ScrollBar2_Change End Sub Private Sub UserForm_Initialize() 'ScrollBarの初期化 With ScrollBar1 .Max = 2100 .Min = 1900 .Value = Year(Date) End With With ScrollBar2 .Max = 12 .Min = 1 .Value = 2 End With End Sub