Tab Rename

bnspool

New Member
Joined
Aug 17, 2011
Messages
11
I am brand new to Excel forums and a rookie macro creator. I am looking for a simple code to rename each new tab to match a selected cell input (in this case cell B9).

What I have works, but triggers this message box every time inputs are made elsewhere on the sheet:

"The name (tab name) is not a valid Sheet name"

Here's the code I'm using:

Sub SheetCreateDated()
Dim newsht As Worksheet, ws As Worksheet
Dim ivalue As String
ivalue = Sheets("Claimant1").Range("B9").Value
For Each ws In Worksheets
If ws.Name = ivalue Then
MsgBox ("There is already a sheet with the name " & "*" & ivalue & "*")
Exit Sub
End If
Next ws
Set newsht = Worksheets.Add
With newsht
.Move After:=Sheets(Sheets.Count)
.Name = ivalue
End With
Sheets("Claimant1").UsedRange.Copy Destination:=newsht.Range("B9")
newsht.Range("A3").Value = ivalue
End Sub

Thanks in advance for any help you can provide!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
That should work provided the employee's name is less than 32 characters long.

Is there anything else going on like event code?
 
Upvote 0
Yes. It works and meets the character limits. However, I still get a message box that says the new name is not a valid sheet name. This message box appears after any entry anywhere else on the sheet.
 
Upvote 0
Right click the sheet tab, select View Code. Is there code there? If so please post it.
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strNew As String, strOld As String
If Target.Cells.Count > 1 Then Exit Sub

With Range("B9")
On Error Resume Next
If Not (Application.Intersect(Target, .DirectPrecedents) Is Nothing) Then
strOld = Me.Name
strNew = CStr(.Value)
Me.Name = strNew

If Me.Name = strOld Then
MsgBox "The name " & strNew & " is not a valid Sheet name"
End If
End If
On Error GoTo 0
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top