除了 Private Sub Worksheet_Change_D(ByVal target As Range) 之外,所有代码均有效。I8:I200 列具有显示另一张工作表的更新更改的公式。如果 I8:I200 显示为已完成,则 F 列应使用这些条件进行更新。如果我单击单元格 I8,它会手动工作,F8 会更改,但它应该自动执行。我有另一个影响 F 列的 VBA 工作表更改,但这是手动更改,所以这很好。这会成为此代码的问题吗?我该如何处理?这是在实际工作表下,而不是 ThisWorkbook 下。
Private Sub Worksheet_Change_D(ByVal target As Range)
Dim WorkRng As Range
Dim rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("I8:I200"), target)
xOffsetColumn = -3
If Not WorkRng Is Nothing Then
Application.EnableEvents = False 'disable events
For Each rng In WorkRng
If rng.Value = "" Then
rng.Offset(0, xOffsetColumn).Value = "Not Started"
Else
If rng.Value = "Completed" Then
rng.Offset(0, xOffsetColumn).Value = "Completed"
Else
If rng.Value = "Pending" Then
rng.Offset(0, xOffsetColumn).Value = "Pending Prior Task"
Else
rng.Offset(0, xOffsetColumn).Value = "Not Started"
End If
End If
End If
Next
Application.EnableEvents = True 'enable events
End If
End Sub