Python eats data
Python eats data

Reputation: 35

Getting error while comparing two sets of data using arrays

In excel 2010, I have to compare two versions (old, new) of the same underlying data

I used arrays to store the old values and the new values and then tried to compare the corresponding values. Where the values are not same, the cell background would become yellow.

Everything works fine till the statement

If vaNewValues(i, j).Value <> vaOldValues(i, j).Value Then

At this statement, I am getting run-time error ‘424’: Object required

Sub File_Comparison()

'Open the old file

OldFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please open old file")
Workbooks.Open Filename:=OldFN
End If

'Store the range of cells into an array 'vaOldValues

vaOldValues = Range("b9:r54").Value

'Close old file

ActiveWorkbook.Close False

'Open the new file
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please open new file")
Workbooks.Open Filename:=NewFN

'Store the range of cells into an array 'vaNewValues
vaNewValues = Range("b9:r54").Value

'i= row
'j=column

For i = 1 To UBound(vaNewValues, 1) 'max row number
For j = 1 To UBound(vaNewValues, 2) 'max column number


*If vaNewValues(i, j).Value <> vaOldValues(i, j).Value Then*

Range("b9:r54").Cells(i, j).Interior.Color = 65535

End If

Next j
Next i

End Sub

Upvotes: 0

Views: 178

Answers (1)

brettdj
brettdj

Reputation: 55682

Working with arrays is not the same as ranges, try this instead to access the value in the array

If vaNewValues(i, j) <> vaOldValues(i, j) Then

Upvotes: 2

Related Questions