vb script to compare data from 2 excel files and write a flag if a match is found.

Posted on 2007-08-06
Last Modified: 2012-06-27
I am trying to write a vb script code that will enable me to read and compare data from 2 excel files. if a matach is found i put a flag. All i need is the part where it binds to the 2 files, workbooks and worksheets. and how to do the comparison. is it like the normal boolean expressions like
if(sheet1.value = sheet2.value)
   They are equal
   Not Equal
Example of the data..
File1                                                                  File 2
   Sheet1                                                                Sheet 1
       Col 2                                                                    col 6                       Flag
         45                                                                          23
         34                                                                          45                      Found a match
its something like this.

thank you.

Question by:amcurso
    LVL 29

    Accepted Solution

    This should get you started:

    Dim wb1, wb2
    Dim ws1, ws2
    Dim xl

    Set xl = CreateObject("Excel.Application")
    Set wb1 = xl.Workbooks.Open("c:\myBook1.xls")
    Set wb2 = xl.Workbooks.Open("c:\myBook2.xls")

    Set wk1 = wbk1.Worksheets(1)
    Set wk2 = wbk2.Worksheets(1)


    LVL 29

    Assisted Solution

    This site has some more useful samples on working with Excel from VBS


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    27 Experts available now in Live!

    Get 1:1 Help Now