I have a program that will highlight a cell if the value does not match the value on a corresponding sheet. It seems to work for the most part, but gives me false positives sometimes. It only gives me the false positive on a certain category it is checking (monetary value). Basically, there are many lines that have a formula at the end that verifies the validity of all categories matching. If any of the 5 categories do not match, the result will be “check,” as opposed to “valid” if they all do match. The program them goes down the column of Valid/Check and steps into another subroutine if the value is check. This will go category by category comparing the two values. It works perfectly to highlight any error, but it sometimes steps into an if statement when the monetary values match. I have attached code, and pictures that show the two values I am comparing are matching numbers, but for whatever reason it still steps in to my if comp1 does not equal comp 2 if statement.
This picture shows CORRECT detections of errors in column G, and false positives in column F.
false positives.png

(I felt obligated to block out descriptions so the money values don’t actually give away private information, but you can see the background highlighting that is happening). Again, any highlighting in column G is correct, any highlighting in F should not be there.

You can see here that when I step through the code it shows the two variables being equal, yet it still steps in to the “if they do not equal then do this” segment of the code. I can’t seem to figure out why it would do this for some and not others, as you can see in the first image, there are highlighted cells in column G that are not triggering the false positive highlight in column F, and some that do. It seems random and I cannot seem to figure out why it randomly wants to step in. Any ideas?

code.png



Sub highlightError()

Dim comp1, comp2, jeType As String
Dim monComp1, monComp2 As Double
Dim r, c As Integer

'Code ommited


'check money value
ActiveCell.Offset(0, 1).Select

If IsEmpty(Selection) Then
    ActiveCell.Value = 0
End If

monComp1 = ActiveCell.Value
r = ActiveCell.Row
c = ActiveCell.Column

Sheets("Journal Entry").Select
Cells(r, c - 1).Select
monComp2 = ActiveCell.Value - ActiveCell.Offset(0, 1).Value

If monComp1 = monComp2 Then
ElseIf monComp1 <> monComp2 Then

    If IsEmpty(ActiveCell) = True Then
        ActiveCell.Offset(0, 1).Select
        
        With ActiveCell
             .Interior.ColorIndex = 6
             .Font.Bold = True
        End With
        
    End If
    
    With ActiveCell
         .Interior.ColorIndex = 6
         .Font.Bold = True
    End With
        
   Sheets("PeopleSoft").Select
  
    Cells(r, c).Select
    With ActiveCell
         .Interior.ColorIndex = 6
         .Font.Bold = True
    End With
   
End If

End Sub