Check for dated sheet
Hi,
Try this - errors if sheet already exists. I assume you only want one
sheet per day/date.
Sub blank1()
Dim oWs As Worksheet
Dim oSheet As Worksheet
Dim shName As String
Set oWs = Sheets("Blank")
On Error GoTo 0
If Not oWs Is Nothing Then
Set oSheet = Nothing
On Error Resume Next
shName = Format(Date - 1, "mm-dd-yyyy")
Set oSheet = Sheets(shName)
On Error GoTo 0
If oSheet Is Nothing Then
oWs.Copy Befo=Sheets(1)
ActiveSheet.Name = shName
Else
MsgBox " Sheet " & shName & " already exists"
End If
End If
End Sub.
HTH
"Mike K" wrote:
I tried the code that Bob gave me and it still errors on a
second macro run. "Run-time error '1004' Cannot rename a
sheet to the same name as another sheet". It adds the
sheet just fine the first time, but if I rerun the macro
it croaks when the sheet name has already been created.
Sub blank1()
Dim oWs As Worksheet
On Error Resume Next
Set oWs = Sheets("Blank")
On Error GoTo 0
If Not oWs Is Nothing Then
oWs.Copy Befo=Sheets(1)
ActiveSheet.Name = Format(Date - 1, "mm-dd-yyyy")
End If
End Sub
Mike
|