ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   My program read the wrong msgbox (https://www.excelbanter.com/excel-programming/393110-my-program-read-wrong-msgbox.html)

anamarie30

My program read the wrong msgbox
 
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

p45cal[_50_]

My program read the wrong msgbox
 
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?
--
p45cal


"anamarie30" wrote:

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


anamarie30

My program read the wrong msgbox
 
I test this code by enter manually the values and for that reason is EXACTLY
0.44

"p45cal" wrote:

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?
--
p45cal


"anamarie30" wrote:

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


p45cal[_50_]

My program read the wrong msgbox
 
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
--
p45cal


"anamarie30" wrote:

I test this code by enter manually the values and for that reason is EXACTLY
0.44

"p45cal" wrote:

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?
--
p45cal


"anamarie30" wrote:

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



All times are GMT +1. The time now is 05:34 PM.

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