Hi when running code to protect workbook I get a message which says "Please revise the entry in A1. It appears to contain one or more illegal characters."

Then it goes to debug but a different sheet each time.

Does anyone know why this is happening?

Thank you

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Set Target = Range("A1")
    If Target = "" Then Exit Sub
    On Error GoTo Badname
    ActiveSheet.Name = Left(Target, 31)
    Exit Sub
Badname:
    MsgBox "Please revise the entry in A1." & Chr(13) _
    & "It appears to contain one or more " & Chr(13) _
    & "illegal characters." & Chr(13)
    Range("A1").Activate
End Sub