PDA

View Full Version : Solved: chk sheet names of 2 wrkbk & delete if not matching



ilyaskazi
06-12-2005, 11:05 PM
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.

xld
06-13-2005, 05:35 AM
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

ilyaskazi
06-14-2005, 03:35 AM
solved perfect... thankyou.

regards,
ilyaskazi