+ Reply to Thread
Results 1 to 2 of 2

Check if Worksheet exists and Insert Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Tacoma, Washington
    MS-Off Ver
    Excel 2007
    Posts
    3

    Check if Worksheet exists and Insert Worksheet

    I want my Macro to check to see if worksheet "Output" exists, and if it dose not then insert a worksheet called "Output" in the second position in the workbook.
    Need help with checking for existence and inserting, naming, and inserting in proper location.

    Your last advice for creating a dynamic help menu was perfect.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Check if Worksheet exists and Insert Worksheet

    Maybe the following might work:
    Option Explicit
    
    Private Sub Workbook_Open()
        Dim shts As Worksheet, newWs As Worksheet
        Dim opBool As Boolean
        opBool = False
        For Each shts In Sheets
            If shts.Name = "Output" Then
                opBool = True
                shts.Select
                Exit For
            End If
        Next shts
        If opBool = False Then
            Application.ScreenUpdating = False
                Sheets(2).Select
                Set newWs = Sheets.Add
                newWs.Name = "Output"
            Application.ScreenUpdating = True
        End If
    End Sub
    The previous code should be pasted into the "ThisWorkbook" module. It will check the workbook when it is first opened. Is this what you require?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1