I'm trying to use Worksheet_Change to unlock certain cells when I change the customer name in the target (C7). When I actually change the name in C7, it responds correctly. However, it also runs the code whenever I press "Enter", regardless if I changed the target cell or not. How do I restrict it to running ONLY when C7 is changed and NOT when I enter data somewhere else on the worksheet?
Here is my code:
Thanks in advance.
Here is my code:
Code:
Sub Worksheet_Change(ByVal Target As Range)
'
' CustomerChange Macro
'
Dim VRange As Range
Set VRange = Range("'Instructions'!C7")
If VRange Is Nothing Then
Sheets("Instructions").Unprotect
Sheets("Instructions").Range("C23:C27,G7,G8,G21,G29,G30").Locked = True
Selection.FormulaHidden = False
Sheets("Instructions").Protect AllowFiltering:=True, AllowUsingPivotTables:=True
Exit Sub
ElseIf VRange = "Customer 1" Then
ActiveSheet.Unprotect
Range("C23:C27").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect AllowFiltering:=True, AllowUsingPivotTables:=True
Exit Sub
ElseIf Range("F7") <> "" Then
ActiveSheet.Unprotect
Range("G7").Select
Selection.Locked = False
Selection.FormulaHidden = False
ElseIf Range("F8") <> "" Then
ActiveSheet.Unprotect
Range("G7").Select
Selection.Locked = False
Selection.FormulaHidden = False
ElseIf Range("F21") <> "" Then
ActiveSheet.Unprotect
Range("G21").Select
Selection.Locked = False
Selection.FormulaHidden = False
ElseIf Range("F29") <> "" Then
ActiveSheet.Unprotect
Range("G29").Select
Selection.Locked = False
Selection.FormulaHidden = False
ElseIf Range("F30") <> "" Then
ActiveSheet.Unprotect
Range("G30").Select
Selection.Locked = False
Selection.FormulaHidden = False
Else
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
End If
End Sub
Thanks in advance.