True Or False, no matter what... it still displays the false statement

  • Thread starter Thread starter rocky640
  • Start date Start date
R

rocky640

True Or False, no matter what... it still displays the false statement

If X = Y then
msgbox("They are equal")
else
msgbox("They are not equal")
end if

Ok, both X and Y are set to 3. But, the message box "They are no
equal" is still shown.

I know that both X and Y is set to 3 because when the macro is runnin
I but my curser over the variable and it tells me it is equal to 3
 
This works for me:

''''''''''''''''''''''''
Dim X As Double, Y As Double
X = 3
Y = 3

If X = Y Then
MsgBox ("They are equal")
Else
MsgBox ("They are not equal")
End If
''''''''''''''''''''''''''''''''''''''
 
Rocky,

How are the variables X and Y declared, and are their values
computed? It might be the case that the inherent rounding issues
with Double or Single variables causes their values to be
unequal. For example, X might be 3.00000000000001 and Y might be
3.000000000002.

What happens if you write your code like

If Abs(X-Y) < 0.0001 Then

You might want to post the code that assigns the values to X and
Y.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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