-1

編集:代わりに ActiveSheet.unprotect を使用すると機能します

私のワークシートが保護されていない場合、次のようにするとうまくいきます!

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とprotectを追加しようとしましたが、それでも機能しません!

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

ヘルプ??

4

1 に答える 1

0

に変更しましたがActiveSheet.Protect、動作します

于 2013-02-08T19:36:20.433 に答える