Reputation: 87
Trying to change cell content in protected sheet, but get password fault stating Caps Lock is on. Code is as follows:
'Change Best Peak Flow and Date Achieved
ActiveSheet.Unprotect Password:=asthma
If Range("R7").Value > Range("F7").Value Then
Range("R7").Select
Selection.Copy
Range("F7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("K7") = Date
Application.CutCopyMode = False
ActiveSheet.Protect Password:=asthma, DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End Sub
Upvotes: 0
Views: 74
Reputation: 3037
You've forgotten to put a pair of quotes around asthma
to make it a string literal, so VBA interprets it as the name of a variable. Since this variable hasn't been declared, its value is an empty string.
You can avoid errors like this by putting Option Explicit
at the start of each module, so the VBA editor will give an error when you try to use an undeclared variable.
Upvotes: 2