Can anyone help me figure out why this isnt working and how to fix it? The values of the variable in the immediate window show that it should be working.
For example if cell "A" contains .122 and cell J contains .121 the code doesnt work whereas if cell "A" contains .122 and cell J contains .123 it does work.
Option Explicit
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer, od As Double, nd As Double, q As Double
i = Target.Row
q = Target.Column
If Range("K" & i).Value = "Out of Service" Or q <> 10 Then Exit Sub
If IsNumeric(Range("J" & i).Value) = False Then
Application.EnableEvents = False 'This must be on to prevent circular reference crash
Cells(i, 10).Interior.Color = vbGreen
Cells(i, 10).Font.Bold = True
Range("J" & i).Value = "In Use"
Application.EnableEvents = True
Exit Sub
End If
od = Range("A" & i).Value + 1.0001
nd = Range("J" & i).Value + 1.0001
If od = nd Then
Application.EnableEvents = False
Cells(i, 10).Interior.ColorIndex = 0
Cells(i, 10).Font.Bold = False
Range("K" & i).Value = "Good"
Application.EnableEvents = True
Exit Sub
End If
If Round(od,4) = Round(nd - 0.001,4) Or Round(od,4) = Round(nd + 0.001,4) Then
Application.EnableEvents = False
Cells(i, 10).Interior.Color = vbYellow
Cells(i, 10).Font.Bold = True
Range("K" & i).Value = "Marginal"
Application.EnableEvents = True
ElseIf Round(od,4) >= Round(nd + 0.002,4) Or Round(od,4) <= Round(nd - 0.002,4) Then
Application.EnableEvents = False
Cells(i, 10).Interior.Color = vbRed
Cells(i, 10).Font.Bold = True
Range("K" & i).Value = "Replace"
Application.EnableEvents = True
End If
End Sub