Consulting

Results 1 to 3 of 3

Thread: Solved: chk sheet names of 2 wrkbk & delete if not matching

  1. #1

    Question Solved: chk sheet names of 2 wrkbk & delete if not matching

    Wrkbk1: MyProject_1
    Wrkbk2: MyProject_2

    Both workbook are opened and Wrkbk1 is active.

    Upon execution, match sheet names of wrkbk1 with wrkb2 and vice versa

    If any sheet does not matching, then delete the sheet from wrkbk1/wrbk2.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,147
    Location
    [VBA]

    Sub test()
    Const Book1 As String = "My_Project_1.xls"
    Const Book2 As String = "My_Project_2.xls"
    Dim oWs As Worksheet
    Dim oTarget As Worksheet

    For Each oWs In Workbooks(Book1).Worksheets
    Set oTarget = Nothing
    On Error Resume Next
    Set oTarget = Workbooks(Book2).Worksheets(oWs.Name)
    On Error GoTo 0
    If oTarget Is Nothing Then
    Application.DisplayAlerts = False
    oWs.Delete
    Application.DisplayAlerts = True
    End If
    Next oWs

    For Each oWs In Workbooks(Book2).Worksheets
    Set oTarget = Nothing
    On Error Resume Next
    Set oTarget = Workbooks(Book1).Worksheets(oWs.Name)
    On Error GoTo 0
    If oTarget Is Nothing Then
    Application.DisplayAlerts = False
    oWs.Delete
    Application.DisplayAlerts = True
    End If
    Next oWs

    End Sub
    [/VBA]

  3. #3

    Thumbs up

    solved perfect... thankyou.

    regards,
    ilyaskazi

Posting Permissions

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