Rename a worksheet after copy...
I think this is what you are looking for...
Sub test()
Dim strNewName As String
strNewName = "DOS" & CInt(Mid("DOS5", 4, 3)) + 1
If SheetExists(strNewName, ThisWorkbook) Then
MsgBox strNewName & " already exists."
Else
Sheets("DOS5").Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
ActiveSheet.Name = strNewName
End If
End Sub
Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...
Jim Thomlinson
"Cathy W" wrote:
Hello. I am using the following code to copy a worksheet named DOS5 into a
workbook that already has a sheet called DOS5. When it gets copied I would
like to rename it to the next sequential sheet number (ie: DOS6). Can
someone help?
bk.Sheets("DOS5").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
Thanks,
Cathy
|