Sub test()
Dim ws As Worksheet, sName As String
sName = "MySheet"
Set ws = Worksheets.Add(after:=ActiveSheet)
On Error Resume Next
ws.Name = sName
If Err.Number = 1004 Then
MsgBox "Cannot rename: " & ws.Name & vbCr & _
sName & " is already in use"
End If
On Error GoTo 0
End Sub
Here "MySheet" is hardcoded, but you may want some other way of giving the
name, an InputBox perhaps.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.