Consulting

Results 1 to 2 of 2

Thread: insert the worksheet if the sheet is missing

  1. #1

    insert the worksheet if the sheet is missing

    Hi,

    I want a macro which can perform the following function.

    Sheet A, Sheet B and Sheet C must appear in the workbook.
    If any one of them (or some of them) is missing, insert the sheet.

    Could you please write me the macro?

    Thanks

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Assuming that Sheet A, etc is merely another blank worksheet ....

    [VBA]
    Option Explicit

    Sub Check()
    Call InsertMissingSheet("Sheet A")
    Call InsertMissingSheet("Sheet B")
    Call InsertMissingSheet("Sheet C")

    End Sub

    Sub InsertMissingSheet(sSheetName As String)
    Dim i As Long

    i = 0
    On Error Resume Next
    i = ThisWorkbook.Worksheets(sSheetName).Index
    On Error GoTo 0

    If i > 0 Then Exit Sub

    ThisWorkbook.Worksheets.Add.Name = sSheetName
    End Sub
    [/VBA]

    If Sheet A, etc. is a specially formated, preset, worksheet, it gets a little more complicated

    Paul

Posting Permissions

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