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!
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!