First, variable wks is undeclared, and you are ignoring errors. Most likely the line
is producing an error which your code is ignoring. I recommend you use Option Explicit to guarantee that all variables are declared.
Also, this is a strange condition to test for:
Also, you are copying the sheet first, and giving the user no opportunity to cancel the operation. You should get the name from the user first, exiting if he changes his mind.
I would suggest this rewrite. Note that sName is declared as Variant, because InputBox returns a Variant. It will be a string if the user entered a string, and it will be FALSE if the user pressed Cancel.
In this solution, if the user does not enter a sheet name, no copy is created. If the user enters a sheet name but the result is invalid, the new sheet is deleted and the user gets an error message.
Bookmarks