|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下。。。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False '关闭屏幕刷新
ss = [p1].Value
Application.EnableEvents = False
If Target.Count = 1 Then
With Target
s = Target.Value
If .Column = 3 And s <> Empty Then
If .Offset(0, 1).Value = Empty Then .Offset(0, 1) = Date
s = .Offset(0, 1).Value
x = IIf(s + 14 > DateSerial(Year(s), Month(s) + 1, 5), _
DateSerial(Year(s), Month(s) + 1, 5), s + 14)
If ss <> Empty Then
If x > ss Then .Offset(0, 2) = ss Else .Offset(0, 2) = x
Else
.Offset(0, 2) = x
End If
ElseIf .Column = 3 Then
.Offset(0, 1).Resize(, 2).ClearContents
End If
If .Column = 4 And s <> Empty Then
x = IIf(s + 14 > DateSerial(Year(s), Month(s) + 1, 5), _
DateSerial(Year(s), Month(s) + 1, 5), s + 14)
If ss <> Empty Then
If x > ss Then .Offset(0, 1) = ss Else .Offset(0, 1) = x
Else
.Offset(0, 1) = x
End If
End If
If Target.Address = "$P$1" Then
If ss <> Empty Then
r = Me.Cells(Me.Rows.Count, 5).End(3).Row
For i = 2 To r
If Me.Cells(i, 5).Value > ss Then Me.Cells(i, 5).Value = ss
Next
Else
For i = 2 To r
s = Me.Cells(i, 4).Value
If s <> Empty Then
x = IIf(s + 14 > DateSerial(Year(s), Month(s) + 1, 5), _
DateSerial(Year(s), Month(s) + 1, 5), s + 14)
Me.Cells(i, 5).Value = x
End If
Next
End If
End If
End With
Else
If Target.MergeCells Then
If Target.Cells(1).Address = "$P$1" Then
r = Me.Cells(Me.Rows.Count, 5).End(3).Row
If ss <> Empty Then
For i = 2 To r
If Me.Cells(i, 5).Value > ss Then Me.Cells(i, 5).Value = ss
Next
Else
For i = 2 To r
s = Me.Cells(i, 4).Value
If s <> Empty Then
x = IIf(s + 14 > DateSerial(Year(s), Month(s) + 1, 5), _
DateSerial(Year(s), Month(s) + 1, 5), s + 14)
Me.Cells(i, 5).Value = x
End If
Next
End If
End If
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True '开启屏幕刷新
End Sub
|
评分
-
1
查看全部评分
-
|