Hello,
I have a userform set up that compares the values of two textboxes ('New' and 'Ref'), which occurs every time either textbox is changed. When 'New' > 'Ref', 'New' should change to a red background.
It is currently telling me that 3 > 22.3 and 5 > 49.15, etc. because when 'New' has 5 or 5.00 and 'Ref' has 49.15, it returns 'New' as red.
When 'Ref' is 0.49 or 4.91, this code works. But when 'Ref' has double digit whole numbers like 49.1, it gets confused and compares the starting '4' in '49' with the single digit '5'.
' if new value is larger than ref value, show red background
If New.Value = "" Or Ref.Value = "" Then
New.BackColor = &H80000005 'white
Else
If New.Value <= Ref.Value Then
New.BackColor = &HC0FFC0 'green
Else
New.BackColor = &HC0C0FF 'red
End If
End If
' (The .Value Type of each textbox is "Variant/String")
I tried using "CDec" but that didn't seem to work. What do I need to do?
New = CDec(New)
Ref = CDec(Ref)
'OR, also tried:
New.Value = CDec(New.Value)
Ref.Value = CDec(Ref.Value)
Thank you much, in advance!
Bookmarks