ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Logical operator inconsistency (https://www.excelbanter.com/excel-programming/363597-logical-operator-inconsistency.html)

KD[_5_]

Logical operator inconsistency
 
Hi All:
I am conditional formatting a userform label based on whether a
calculated value is greater than a number assigned to a State. The
assigned number is retrieved in a vlookup. Green if
lLastScoreCutLine, red if false. Named Range lLastScore is the
calculated field and Named Range Cutline is the State value.
Unfortunately the rest of the code is too long for me too post so it
will not work if you cut and paste.

Me.lCutLine.Caption = ThisWorkbook.Worksheets("Input
Form").Range("CutLine").Text

Me.lLastScore.Caption = ThisWorkbook.Worksheets("Prioritization
Output").Range("Score").Text
If Me.lLastScore.Caption Me.lCutLine.Caption Then
Me.lLastScore.ForeColor = &HC000&
Else
Me.lLastScore.ForeColor = &HFF&
End If

If Me.lLastScore.Caption Me.lCutLine.Caption Then
Me.Label61.ForeColor = &HC000&
Else
Me.Label61.ForeColor = &HFF&
End If

The code does not throw an error, but it is inconsistent. It works for
Colorado, but not for Texas and New Mexico. I have double checked
lookup table formatting and they table is consistent all #.00 number.
They evaluate at:

CutLine (Colorado)="1.94"
CutLine (Texas)="3.65"
lLastScore="12.2" or "1.1" or "3.9" or "100.6"

The quotes indicate they are coming in as strings. Can I bring them in
as numeric values? The .Value property does not work.

Thanks. This has me stumped.......

James


NickHK

Logical operator inconsistency
 
James,
You are comparing strings, not their numerical value. Hence "12" < "2"
because "1" < "2" .
If you mean to compare their numeric value, do CSng(Me.lLastScore.Caption)
etc.

NickHK

"KD" wrote in message
oups.com...
Hi All:
I am conditional formatting a userform label based on whether a
calculated value is greater than a number assigned to a State. The
assigned number is retrieved in a vlookup. Green if
lLastScoreCutLine, red if false. Named Range lLastScore is the
calculated field and Named Range Cutline is the State value.
Unfortunately the rest of the code is too long for me too post so it
will not work if you cut and paste.

Me.lCutLine.Caption = ThisWorkbook.Worksheets("Input
Form").Range("CutLine").Text

Me.lLastScore.Caption = ThisWorkbook.Worksheets("Prioritization
Output").Range("Score").Text
If Me.lLastScore.Caption Me.lCutLine.Caption Then
Me.lLastScore.ForeColor = &HC000&
Else
Me.lLastScore.ForeColor = &HFF&
End If

If Me.lLastScore.Caption Me.lCutLine.Caption Then
Me.Label61.ForeColor = &HC000&
Else
Me.Label61.ForeColor = &HFF&
End If

The code does not throw an error, but it is inconsistent. It works for
Colorado, but not for Texas and New Mexico. I have double checked
lookup table formatting and they table is consistent all #.00 number.
They evaluate at:

CutLine (Colorado)="1.94"
CutLine (Texas)="3.65"
lLastScore="12.2" or "1.1" or "3.9" or "100.6"

The quotes indicate they are coming in as strings. Can I bring them in
as numeric values? The .Value property does not work.

Thanks. This has me stumped.......

James





All times are GMT +1. The time now is 07:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com