|
▼溜息吐息 さん:
'A1 に年、B1に月を入力するとRange("A4:A35")に日付を入力するマクロを見つけました。
B1には、=Today()・・・書式の設定で例えば10月に変更して活用されては?
後はアレンジしてください。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim themonth As Integer
Dim theyear As Integer
Dim days As Integer
With Target
If IsEmpty(.Value) Then Exit Sub
If Not IsNumeric(.Value) Then Exit Sub
If .Count > 1 Then Exit Sub
Application.EnableEvents = False
If .Address(0, 0) = "A1" Or .Address(0, 0) = "B1" Then
If Range("A1").Value <> "" And Range("B1").Value <> "" And _
IsNumeric(Range("A1").Value) And IsNumeric(Range("B1").Value) Then
Range("A4:A35").ClearContents
theyear = Range("A1").Value
themonth = WorksheetFunction.RoundDown(Range("B1").Value, 0)
If themonth >= 1 And themonth <= 12 Then
With Range("A4")
For days = 1 To Day(DateSerial(theyear, themonth + 1, 1) - 1)
.Offset(days - 1).Value = DateSerial(theyear, themonth, days)
Next
End With
Else
MsgBox "月の値は、1〜12を入力してください。"
Range("B1").Select
End If
End If
End If
End With
Application.EnableEvents = True
End Sub
|
|