If rs.RecordCount > 0 Then .Range("AF4").Value = pjno MsgBox "This project number does exists Please create a new one !", 16 .Range("A1:AH56").Locked = False .Range("F6:M6").Locked = True ActiveSheet.Protect Password:="locked" Exit Sub Else .Range("AF4").Value = pjno End If