1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

  2. 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


  3. 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

Discussion in 'VBA Macros' started by coolkiran, Dec 4, 2018.

  1. coolkiran

    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 (vb):

    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"
      Set wsnew = owb.Sheets.Add
      wsnew.Name = a
      End If
    Next ws1
    Next ws

Share This Page