Skip add page if code

gottimd

Well-known Member
Joined
Jul 29, 2002
Messages
501
I have the following macro which is a "Workbook_Open" event:

Code:
Sheets("Data").Select
If Sheets("Data").Range("F4").Value = "TTC.INP" Then
    Sheets("Companies").Select
    Sheets.Add
    ActiveSheet.Name = "Version Notes"
    ActiveWorkbook.Sheets("Version Notes").Tab.ColorIndex = 8
    Range("A1:O388").Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("Data").Select
    End If

But each time it is opened it adds this page. How do I write it so that if the page "Version Notes" already exists, to skip this macro?

Thanks for your help in advance.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Does this work for you?
Code:
On Error Resume Next
Sheets("Version Notes").Activate
On Error GoTo 0
If ActiveSheet.Name = "Version Notes" Then Exit Sub
If Sheets("Data").Range("F4").Value = "TTC.INP" Then
    Sheets.Add
    ActiveSheet.Name = "Version Notes"
    ActiveWorkbook.Sheets("Version Notes").Tab.ColorIndex = 8
    Range("A1:O388").Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("Data").Select
End If
 
Upvote 0
Thanks.....will the "Then Exit Sub" line stop the macro completely, because after this section of the code (after the End If) there is another section of the code.
 
Upvote 0
gottimd said:
Thanks.....will the "Then Exit Sub" line stop the macro completely, because after this section of the code (after the End If) there is another section of the code.

Yes it would. In that case, change the code to something like:
Code:
On Error Resume Next
Sheets("Version Notes").Activate
On Error GoTo 0
If ActiveSheet.Name = "Version Notes" Then GoTo NextStep
If Sheets("Data").Range("F4").Value = "TTC.INP" Then
    Sheets.Add
    ActiveSheet.Name = "Version Notes"
    ActiveWorkbook.Sheets("Version Notes").Tab.ColorIndex = 8
    Range("A1:O388").Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("Data").Select
End If
NextStep:
'the rest of your code
 
Upvote 0

Forum statistics

Threads
1,196,030
Messages
6,012,962
Members
441,741
Latest member
jlburn

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