Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

Compare Two Excel Files


Add This Code to My Favourite List
Enter Email

Contributed By Sandeep Jadhav
Date 2016-04-12 10:07:45

' Compare two excel files 

'create two excel sheets compare1.xls and compare2.xls
'compare1.xls contains  
'10     15
'20     16
'30     17
'31     18
'32     13
'33     21
'34     22
'35     29
'36     34
'37     37
'21     40

'Compare2.xls contains  
'10     15
'20     16
'30     17
'31     18
'32     13
'29     21
'34     57
'35     29
'36     34
'37     41
'21     40


Set xl=createobject("Excel.Application")
xl.visible="True"

'Open workbook s to compare
Set compare1=xl.workbooks.Open("D:\WORK\QTP\QTPSTUFF\Datasheet\Compare1.xls")
Set compare2=xl.workbooks.Open("D:\WORK\QTP\QTPSTUFF\Datasheet\Compare2.xls")

Set CompareSheet1=compare1.sheets("sheet1")
Set CompareSheet2=compare2.sheets("sheet1")

For each cell in CompareSheet1.UsedRange
  If cell.value <>          C     compareSheet2.Range(Cell.Address).value Then

                ' highlight the cell if mismatch exist
        cell.Interior.ColorIndex = 6
        End If
Next

'Close workbooks
Compare1.close
Compare2.close

'Close the application
xl.Quit

Download Above Code

Comments:



Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *