-1
编辑:工作,如果我使用ActiveSheet.unprotect代替EXCEL;另一种细胞后改变细胞的保护工作表更新
确定的,如果我的工作是不受保护的,下面的工作正常!
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Reset_EnableEvents
Application.EnableEvents = False
If Not Intersect(Target, Range("D6:G6")) Is Nothing Then 'do the following if D6 is updated
Range("D7").Interior.ColorIndex = 15
If Range("D6") = "No" Then
Range("D7").Interior.ColorIndex = 38
End If
End If
If Not Intersect(Target, Range("D7:G7")) Is Nothing Then 'do the following if D6 is updated
If Range("D7") <> "" Then
Range("D7").Interior.ColorIndex = 15
End If
End If
If Not Intersect(Target, Range("e12:f12")) Is Nothing Then 'do the following if E12:F12 is updated
Range("d28").Value = Range("e12").Value 'set d28 to date entered in e12
Range("c23").Interior.ColorIndex = 36 ' reset color of cell c23
If Range("e12") = "" Then ' do the following if e12 is empty
Range("c39") = Chr(34) & "Do you work period?" & Chr(34)
Else
Range("c39") = Chr(34) & "Do you work beyond " & Range("e13").Text & " (approx. period)?" & Chr(34)
If Date >= Range("e15").Value Then
Range("c23").Interior.ColorIndex = 3
End If
End If
End If
If Not Intersect(Target, Range("E32")) Is Nothing Then 'do the following if E32 is updated
If Range("e32") = "Yes" Then
MsgBox "Please have the client complete a MVA Questionnaire."
End If
End If
If Not Intersect(Target, Range("E41")) Is Nothing Then 'do the following if E41 is updated
If Range("e41") = "Yes" Then
Range("d42").Interior.ColorIndex = 38
ElseIf Range("e41") = "No" Then
Range("d42").Interior.ColorIndex = 36
Range("d42") = "Not Required"
ElseIf Range("e41") = "" Then
Range("d42").Interior.ColorIndex = 36
Range("d42") = ""
End If
End If
Reset_EnableEvents:
Application.EnableEvents = True
End Sub
但是当我保护工作表,并且允许被选择仅锁定单元,以及片材添加密码,上述细胞的背景颜色和单元格的值不更新
我尝试添加activeworksheet.unprotect和保护在开始和结束,它仍然不会工作!
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Reset_EnableEvents
Application.EnableEvents = False
'ActiveWorkSheet.Unprotect Password:="a"
`..... all the if not intersect
ActiveWorkSheet.Protect Password:="a"
Reset_EnableEvents:
Application.EnableEvents = True
End Sub
我也试图把保护和取消保护在每个if语句,它仍然没有工作,
If Not Intersect(Target, Range("e12:f12")) Is Nothing Then 'do the following if E12:F12 is updated
ActiveWorkSheet.Unprotect Password:="a"
Range("d28").Value = Range("e12").Value 'set d28 to date entered in e12
Range("c23").Interior.ColorIndex = 36 ' reset color of cell c23
If Range("e12") = "" Then ' do the following if e12 is empty
Range("c39") = Chr(34) & "Do you work period?" & Chr(34)
Else
Range("c39") = Chr(34) & "Do you work beyond " & Range("e13").Text & " (approx. period)?" & Chr(34)
If Date >= Range("e15").Value Then
Range("c23").Interior.ColorIndex = 3
End If
End If
ActiveWorkSheet.Protect Password:="a"
End If
帮助?