|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub Worksheet_Change(ByVal Target As Range)
Dim currentMonth As Integer
currentMonth = Month(Date)
Dim lastDay As Integer
lastDay = Day(DateSerial(Year(Date), currentMonth + 1, 1) - 1)
' 如果是2月份
If currentMonth = 2 Then
' 禁止输入3月份的前三天
If Target.Column > 28 And Target.Column < 32 Then
Target.Locked = True
MsgBox "2月份只有" & lastDay & "天,最后三列不能输入。", vbExclamation, "注意"
End If
' 如果是4、6、9、11月份
ElseIf currentMonth = 4 Or currentMonth = 6 Or currentMonth = 9 Or currentMonth = 11 Then
' 禁止输入最后一列
If Target.Column = 31 Then
Target.Locked = True
MsgBox currentMonth & "月份只有30天,最后一列不能输入。", vbExclamation, "注意"
End If
End If
End Sub |
|