• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Compare 2 workbooks

coolkiran

Member
Hello All

I have a requirement in excel macro.

I have 2 workbooks, Say A and B

A Workbook contains, sheet 1, sheet2 and sheet3

B Workbook contains sheet4

Now i need to compare 2 workbooks, if missing sheets in Workbook B, then need to add sheets from Workbook A

So finally, B workbook should contain : Sheet 1, sheet 2, sheet 3 and sheet 4.

Tried below code but its not working.

Code:
Set act = ThisWorkbook
path = Sheet1.TextBox1.Text
Set owb = Workbooks.Open(Filename:=path)

For Each ws In ThisWorkbook.Worksheets
a = ws.Name
For Each ws1 In owb.Worksheets
  If ws1.Name = a Then
  MsgBox "Found"
  Else
  Set wsnew = owb.Sheets.Add
  wsnew.Name = a
  End If
Next ws1
Next ws
 
Top