My program read the wrong msgbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My code in the if case that state that "myCDR.Value = CDLL" do not give me
the msgbox carrectly. When I run my code and myCDR.Value = 0.44=CDLL the
msgbox box that gave me is that is state that "myCDR.Value < CDLL" and I do
not know why this occur. Suggestions will be appreciated. My code is:

------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

Dim CDR As Range
Dim myCDR As Range
Dim CDLL As Variant
Dim CDUL As Variant

Set CDR = ThisWorkbook.Sheets("PERIOD 1").Range("E66")

Set CDLL = ThisWorkbook.Sheets("LIMITS").Range("A3")
Set CDUL = ThisWorkbook.Sheets("LIMITS").Range("B3")

For Each myCDR In CDR
If IsEmpty(myCDR.Value) Or Trim(myCDR.Value) = "" Then
myCDR.Interior.ColorIndex = 15
Else
If myCDR.Value > CDLL And myCDR.Value < CDUL Then
myCDR.Interior.ColorIndex = 15
Else
If myCDR.Value < CDLL Then
MsgBox "LOT EXCEED THE COSMETIC DEFECT LOWER LIMIT (" &
CDLL & ")!"
myCDR.Interior.ColorIndex = 3
Else
If myCDR.Value > CDUL Then
MsgBox "LOT EXCEED THE COSMETIC DEFECT UPPER LIMIT ("
& CDUL & ")!"
myCDR.Interior.ColorIndex = 3
Else
If myCDR.Value = CDLL Then
MsgBox "LOT REACH THE COSMETIC DEFECT LOWER LIMIT
(" & CDLL & ")!"
myCDR.Interior.ColorIndex = 3
Else
If myCDR.Value = CDUL Then
MsgBox "LOT REACH THE COSMETIC DEFECT UPPER
LIMIT (" & CDUL & ")!"
myCDR.Interior.ColorIndex = 3
End If
End If
End If
End If
End If
End If
Next
End Sub
 
It seems to be all right when I tested it. Are you sure that both values are
EXACTLY 0.44? Try manually entering BOTH values and test again. I suspect
that one of them is not quite .44, perhaps due to a calculation or rounding?
 
I test this code by enter manually the values and for that reason is EXACTLY
0.44
 
One way I got to getting the same message was if in the cell containing CDLL
was this:
O.44
or
o.44
as opposed to 0.44

Another stab in the dark: Check whether all the three cells are formatted in
the same way.

p45cal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top