I have an excel workbook with 2 worksheets, each of them composed of 60 rows and 7 columns (first column consists of text, the rest only numbers).
I found VBA code in order to compare the values of the 2 sheets. If there is a difference, the cell is filled red, but there is an issue with the columns containing numbers:
Cell in 1st Sheet Value: 6102.75
Cell in 1st Sheet Value: 6102.75000001
--> The cell is highlighted red.
Which changes should I make in the code in order not to highlight the cell, if the numbers are equal up to 4 demical points? I think that I have to make a change in the code, to compare separately for text and numbers.
Sub compareSheets(shtBefore As String, shtAfter As String)
Dim mycell As Range
Dim mydiffs As Integer
For Each mycell In ActiveWorkbook.Worksheets(shtAfter).UsedRange
If Not mycell.Value = ActiveWorkbook.Worksheets(shtBefore).Cells(mycell.Row, mycell.Column).Value Then
mycell.Interior.Color = vbRed
mydiffs = mydiffs + 1
Next
'Display a message box stating the number of differences found
MsgBox mydiffs & " differences found", vbInformation
ActiveWorkbook.Sheets(shtAfter).Select
End Sub
Looking forward to your comments