Assuming that cell B5 and K10 is not locked, the code should be :
Private Sub Worksheet_Change(ByVal Target As Range)
Dim str1 As String
If Target.Address(0, 0) = "K10" Then
Range("B5").ClearContents
On Error Resume Next
Range("B5").Validation.Delete
On Error GoTo 0
str1 = LCase(Target.Value)
Me.Unprotect Password:="abc"
If InStr(1, str1, "@gmail.com") Then
Range("B5").Validation.Add Type:=xlValidateList, Formula1:="=vld_gmail"
ElseIf InStr(1, str1, "hotmail.com") Then
Range("B5").Validation.Add Type:=xlValidateList, Formula1:="=vld_hotmail"
Else
Range("B5").Validation.Add Type:=xlValidateList, Formula1:="=vld_all"
End If
Me.Protect Password:="abc", UserinterfaceOnly:=True
End If
End Sub
If above code is not worked, probably caused by other code that you have (as you stated here, you have 5 modules of code) :

Originally Posted by
sandu1
Hello,
I am difficulties in running macro on protected sheets.
I have 5 modules also codes on each sheet. Now, I have to protect the sheet for unauthorized user input.
Its throwing an error while I try to execute the code now. Please suggest.
Thanks
Sandu
and we can't help without seeing all your code that may cause this, you need to post your workbook so we can analyze the problem.
Bookmarks