Rename sheet if current sheet name exists
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
|