Tuesday, May 24, 2011

Compare 2 Excel sheets cell by cell

This code will open two excel sheet and compare each sheet cell by cell, if any changes there in cells , it will highlight the cells in red color in the first sheet.
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and
Settingsmohan.kakarlaDesktopDocs2.xls”)
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
cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing

for Technical interviews:

http://no1tutorial.com/

learn step by step technologies:


http://no1tutorial.com/

1 comment:

  1. Change-Pro for Excel enables business users to compare two Excel documents for changes.
    With Change-Pro for Excel' s patent-pending technology, you can view changes made to Excel values and Excel formulas,along with comparing row and column changes in spreadsheets.

    compare excel worksheets

    ReplyDelete