Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Negative Numbers Comparison 1

Status
Not open for further replies.

caerdydd

Programmer
Mar 2, 2004
35
GB
Hello all
Not sure how to resolve this one but hoping someone could help.

My line of code is....

If cl.Value <> "" And cl.Value <= cl.Offset(0, 4).Value

If this is true then a popup occurs with certain data in it.

In some cases, but not all, cl.value would be -0.77 and cl.offset would be -1.08. Therefore, the pop up should not appear because the criteria in the if statement has not been met (-0.77 is not lower than -1.08). But in excel the pop-up has been occuring.
It seems that when two negative numbers are being compared excel does not recognise them. It recognises one negative compared against a positive though.
Has anyone seen this before and resolved it. I can't think how to through formatting etc etc.
Thanks & best regards
 
Hi,

Are you ABSOLUTELY sure of the values being compared?

Try sticking a msgbox in your code where the popup should occur to display the values.

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Hi,

Are you ABSOLUTELY sure of the values being compared?

Try sticking a msgbox in your code where the popup should occur to display the values.

Better yet, display the values in a Watch Window and STEP thru your code.

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Use a if statement to test for the value if negative then the IF that you posted.

-Laughter works miracles.
 
What about this ?
If cl.Value <> "" And CDbl(cl.Value) <= CDbl(cl.Offset(0, 4).Value)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi
Thanks for the posts.
Skipped through the code and added values to the watch window. This gave back what i was expecting to see i.e the correct values from the sheet. I also formatted the values just to make sure.
I did not know of the CDbl function before, I am testing a larger batch of values but this seems to have solved the problem. Thanks PHV.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top