Hello everyone,
I have a worksheet that has a formula in K9, that is a looking up an account number (in k5) to check membership status. I'd like to have k9 locked and protected unless the override checkbox (activeX) is selected. If it's selected, I'd like the worksheet to unprotect, unlock the cell, then reprotect. After it's protected again with the check box selected, the box will allow an override value of Yes or No only. If the override checkbox is unselected subsequently (false), the workbook will unprotect, lock cell again, replace value with formula, then protect.
With the code below (I am very new to VBA with no previous coding experience), I keep getting an "End With" error.
Any help is very much appreciated. Thank you all!
Private Sub WineClubOverride_Click()
Dim rMyRng As Range
With ActiveSheet.ActiveWorkSheet.Unprotect
Set rMyRng = Range("k9")
Range("K9").Locked = False
rMyRng.Formula = "=IFERROR(IF(VLOOKUP(K5,'Wine Club List'!$K$8:$L$200,2,FALSE)<>0,""Yes"",""No""),""No"")"
Range("K9").Locked = True
With ActiveSheet.ActiveWorkSheet.Protect
End With
If WineClubOverride.Value = True Then ActiveWorkSheet.Unprotect
If WineClubOverride.Value = True Then Selection.Locked = False
If WineClubOverride.Value = True Then rMyRng.Value = rMyRng.Value
If WineClubOverride.Value = True Then ActiveWorkSheet.Protect
End With
End Sub
Bookmarks