|
これでどうかな・・? テストはしてませんが。
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim MyD As Integer, AdM As Integer
If Intersect(Target, Range("B20:B350")) Is _
Nothing Then Exit Sub
With Target
If .Count > 1 Then Exit Sub
If IsEmpty(.Value) Then Exit Sub
If Not IsNumeric(.Value) Then Exit Sub
If .Value < 1 Or .Value > 31 Then Exit Sub
MyD = .Value
End With
If Day(Date) >= 23 Then
AdM = 2
Else
AdM = 1
End If
Application.Enablevents = False
If Day(DateSerial(Year(Date), Month(Date) + AdM, 0)) > MyD Then
MsgBox MyD & " 日は存在しません", 48
Else
Target.Value = _
DateSerial(Year(Date), Month(Date) + (AdM - 1), MyD)
Target.NumberFormat = "yyyy/m/d"
End If
Application.Enablevents = True
End Sub
|
|