Header Ads

VB script to compare two excel sheets

This is a fantastic code to compare two excel sheets.Basically this can be treated as Lean project.:)
ExcelFilePath1 = InputBox("Please Enter the Path of first Excel File")
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(ExcelFilePath1) = false )Then
msgbox ExcelFilePath1 & " doesn't exist."
End If
ExcelFilePath2 = InputBox("Please Enter the Path of second Excel File")
If (fso.FileExists(ExcelFilePath2) = false )Then
msgbox ExcelFilePath2 & " doesn't exist."
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = false

Set objWorkbook1 = objExcel.Workbooks.Open(ExcelFilePath1)
Set objWorkbook2 = objExcel.Workbooks.Open(ExcelFilePath2)

Set objWorksheet1= objWorkbook1.Worksheets(1)

Set objWorksheet2= objWorkbook2.Worksheets(1)

For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then

'Highlights in green color if any changes in cells (for the first file)
cell.Interior.ColorIndex = 4
'Highlights the same cell in the Second file
objWorksheet2.range(cell.Address).interior.colorIndex = 4

cell.Interior.ColorIndex = 0
End If

ObjExcel.displayAlerts = False


set objExcel=nothing

msgbox "It is Done dude"
Powered by Blogger.