我有一些正在使用的工具中开发的代码,该工具会根据另一个单元格的变化执行一些基本的计算以添加日期等。在为其创建的工作表中,它可以正常工作,但是,当我将它复制到另一个工作表模块以执行类似任务(添加了两个额外的列)时,它似乎无法正常工作。我已经更改了引用,以解决另外两列的问题,并且我没有收到任何错误消息,只是没有进行应有的计算。我是VBA新手,似乎无法弄清楚。预先感谢您的帮助!
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo SelectError:
Oval = Target.Value
SelectError:
End Sub
Private Sub Worksheet_Change2(ByVal Target As Range)
If Not Intersect(Target, Range("G11:G202")) Is Nothing Then
On Error GoTo Eerror:
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect Password:="Password"
'Dim TarAddress As String
Range(Target.Address).Select ''''DO NOT DELETE, PREVENTS LOOP
If Range(Target.Address).Value <> 0 Then
Range(Target.Address).Offset(0, 1).Value = Date
'Update Budget
If Range(Target.Address).Offset(0, 5).Value = 0 Then
Range(Target.Address).Offset(0, 5).Value = Range(Target.Address).Value
End If
If Range(Target.Address).Value <> 0 Then
Range(Target.Address).Offset(0, 6).Value = Range(Target.Address).Value
End If
'Set Task Status to Not Started in Cancelled
If Range(Target.Address).Offset(0, 2).Value = "Cancelled" Then
Range(Target.Address).Offset(0, 2).Value = "Not Started"
End If
End If
Eerror:
ActiveWorkbook.Protect Password:="Password"
End If
If Not Intersect(Target, Range("I11:I202")) Is Nothing Then
On Error GoTo GError:
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect Password:="Password"
'Dim TarAddress As String
Range(Target.Address).Select ''''DO NOT DELETE, PREVENTS LOOP
'Mark Complete Date
If Range(Target.Address).Value = "Complete" Or Range(Target.Address).Value = "Complete w/ Issues" Then
Range(Target.Address).Offset(0, 2).Value = Date
Range(Target.Address).Offset(0, -2).Value = 0
End If
'Mark Start Date w/ Complete Date if Blank
If (Range(Target.Address).Value = "Complete" Or Range(Target.Address).Value = "Complete w/ Issues") And Range(Target.Address).Offset(0, 1).Value = "" Then
Range(Target.Address).Offset(0, 1).Value = Date
End If
'Mark Start Date
If Range(Target.Address).Value = "In Progress" And Range(Target.Address).Offset(0, 1).Value = "" Then
Range(Target.Address).Offset(0, 1).Value = Date
End If
'Mark Cancel Date
If Range(Target.Address).Value = "Cancelled" And Range(Target.Address).Offset(0, 8).Value = 1 Then
Range(Target.Address).Offset(0, 13).Value = Date
End If
GError:
ActiveWorkbook.Protect Password:="Password"
End If
End Sub
ETA:我不知道是否是因为它在表单中还是在模块中,但是它不会让我单步执行代码来跟踪它。我期望的一个示例是,如果我在G列的单元格中输入一个大于0的值,它将使用今天的日期更新下一个单元格,然后将该值复制并粘贴到5列和6列的单元格中,以及其他一些内容。当我输入一个值时,它不会像这样进行任何更改,也不会给出错误消息。工作表保持不变。