View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron5440 Ron5440 is offline
external usenet poster
 
Posts: 16
Default Rename sheet if current sheet name exists

Thanks OssieMac...
I modified as such to make work...I used CurSht to set my current sheet name
after checking to see if the sheet existed to get back to the correct sheet.

Sheets.Add
Rdate = Month(Date) & " " & Day(Date) & " " & Year(Date)
CurSht = ActiveSheet.Name

Do
On Error Resume Next
Worksheets(Rdate).Select
If Err.Number 0 Then
On Error GoTo 0
Worksheets(CurSht).Select
Exit Do 'Worksheet does not exist
Else
On Error GoTo 0
x = x + 1
Rdate = (Left(Rdate, 10) & " (" & x & ")")
End If
Loop
ActiveSheet.Name = Rdate



"OssieMac" wrote:

Hi ron,

Sub NameWorkSheet()

Dim Rdate As String
Dim x As Integer
Dim strDateFormat As String

'Edit "dd-mm-yy" to required
'date format for worksheet
strDateFormat = "dd-mm-yy"
Rdate = Format(Date, strDateFormat)

Do
On Error Resume Next
Worksheets(Rdate).Select
If Err.Number 0 Then
On Error GoTo 0
Exit Do 'Worksheet does not exist
Else
On Error GoTo 0
x = x + 1
Rdate = Format(Date, strDateFormat) _
& " (" & x & ")"
End If
Loop

'worksheet must be added after test to ensure
'that it is the active sheet for naming
Sheets.Add After:=Sheets(Sheets.Count)

ActiveSheet.Name = Rdate

End Sub

--
Regards,

OssieMac