Renaming wrong worksheet. Why?
It looks to me like it is renaming the sheet it is told to rename.
On Error GoTo TryAgain
Sheets(Sheets.Count).Name = xName
On Error GoTo 0
'Set CopySheetAnalyst = Sheets(Sheets.Count)
'Exit Function
'TryAgain:
x = x + 1
xName = Basename & "-" & x
It is told that the last sheet is xName then it is told to rename the last
sheet.
"TKM" wrote in message
...
I noticed this code is naming the wrong worksheet.. It assumes the newest
sheet is the one to be renamed and keeps renaming "sheet3". Any help
appreciated.
Public Function CopySheetAnalyst(xlSheet As Worksheet, Index) As Worksheet
'
' Macro2 Macro
' Macro recorded 7/11/2003 by SILVESC
'
Dim xName As String
Dim Basename As String
Dim x As Long
Call xlSheet.Copy(After:=Sheets(Sheets.Count))
Basename = Worksheets("CoverSheet").Range("B5").Offset(0, Index).Value
xName = Basename
On Error GoTo TryAgain
Sheets(Sheets.Count).Name = xName
On Error GoTo 0
Set CopySheetAnalyst = Sheets(Sheets.Count)
Exit Function
TryAgain:
x = x + 1
xName = Basename & "-" & x
Resume
End Function
|