-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
幫助?