I have got a function to compare two xls files
it skips cells if a third spreadsheet has a marker in that cell.
It works ok but I need to make it quicker.
It seems that the delay is caused by reading from cells one at a time.
Any suggestions gratefully received
Thanks
Snuv
"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary
it skips cells if a third spreadsheet has a marker in that cell.
It works ok but I need to make it quicker.
It seems that the delay is caused by reading from cells one at a time.
Any suggestions gratefully received
Code:
Private Function comparefiles(ByVal testfile As String, ByVal samplefile As String, ByVal exclusionsFile As String) As Integer
Dim RetVal As Integer = 0
Dim testBook As Excel.Workbook = m_ExcelApp.Workbooks.Open(testfile)
Dim sampleBook As Excel.Workbook = m_ExcelApp.Workbooks.Open(samplefile)
Dim exclusionBook As Excel.Workbook = m_ExcelApp.Workbooks.Open(exclusionsFile)
Dim testSheet As Excel.Worksheet = testBook.Sheets.Item(1)
Dim sampleSheet As Excel.Worksheet = sampleBook.Sheets.Item(1)
Dim exclusionSheet As Excel.Worksheet = exclusionBook.Sheets.Item(1)
'for each column in the work book
For i As Integer = 1 To MAX_COL
'for each row in the work book
For j As Integer = 1 To MAX_ROW
'check whether to ignore this string
Dim exclusionString As String = exclusionSheet.Cells(j, i).Value
If exclusionString Is Nothing Then
'get the values to compare
Dim testString As String = testSheet.Cells(j, i).Value
Dim sampleString As String = sampleSheet.Cells(j, i).Value
If IsNumeric(testString) Then
If IsNumeric(sampleString) Then
If Not numericComparison(testString, sampleString) Then
RetVal += 1
End If
Else
'They are different
RetVal += 1
End If
ElseIf Not StringComparison(testString, sampleString) Then
'Do a string comparison
RetVal += 1
End If
End If
Next
Next
If RetVal = 0 Then
Log(resultsPath, samplefile & ":- Match")
Else
Log(resultsPath, samplefile & " did not match" & testfile & " : Error count = " & RetVal)
End If
testBook.Close(Savechanges:=False)
sampleBook.Close(Savechanges:=False)
exclusionBook.Close(Savechanges:=False)
End Function
Thanks
Snuv
"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary