If Sheet Exist, Then Go to Newly Created Sheet

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All
I have the following Code
VBA Code:
For Each sht In ActiveWorkbook.Worksheets
    If sht.Visible And sht.Name = "ECD" Then
    sht.Select

The problem is if the sheet "ECD" already exist in the workbook, then I need to go to a newly created sheet
(already created so every day creates a new day sheet)
with this code:
Code:
.Name = Format(Date, "MM-DD-YYYY")

Is this possible?
Thanks for the hep
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
See if this does what you want:
VBA Code:
Sub CreateNewSheetIf()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
    If sht.Name = "ECD" Then
        If Not SheetExists(Format(Date, "MM-DD-YYYY")) Then
            Sheets.Add after:=Sheets(Sheets.Count)
            ActiveSheet.Name = Format(Date, "MM-DD-YYYY")
        Else
            MsgBox "A sheet named " & Format(Date, "MM-DD-YYYY") & " already exists"
        End If
    End If
Next sht
End Sub
Function SheetExists(shName As String) As Boolean
SheetExists = False
For Each sh In ActiveWorkbook.Sheets
    If sh.Name = shName Then
        SheetExists = True
        Exit For
    End If
 Next sh
End Function
 
Upvote 0
Sort of...
You've given me some good ideas.
Let me play around with it for awhile.
Thanks for the help!
 
Upvote 0
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top