I few days ago I wrote several lines of code that should take two Excel files and compare each sheet for changes. The changes and the corresponding sheet are marked in yellow. Now I only want to give used cells a color that have a specific difference. For example only cells which have a difference of > 1000000. I tried CDBl and .isnumeric but I am not able to get a solution.
Sub Excelcomparison()
Dim Msg As String
Dim Old As String
Dim DataOld As String
Dim wb1 As Workbook, wb2 As Workbook, wb3 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
MsgOne = "Select old file for comparison"
Style = vbOKOnly
Response = MsgBox(MsgOne, Style)
Neu = Application.GetOpenFilename("Excel (*.xlsx), *.xlsx")
DataOld = Mid(Old, InStrRev(Old, "\") + 1)
Workbooks.Open Filename:=Old
Set wb1 = ThisWorkbook
Set wb2 = Workbooks(DataOld)
For Each ws1 In wb1.Worksheets
For Each ws2 In wb2.Worksheets
If ws1.Name = ws2.Name Then
For Each cell In ws1.UsedRange.Cells
If cell.Value <> ws2.Range(cell.Address).Value Then
On Error Resume Next
cell.Interior.Color = vbYellow
ws1.Tab.Color = vbYellow
End If
Next cell
End If
Next ws2
Next ws1
End Sub