View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leo Heuser[_2_] Leo Heuser[_2_] is offline
external usenet poster
 
Posts: 111
Default Comparing negative number

Hi

You may *format* a negative number as (50)
in Excel (for -50), but the format is not recognized as
a negative number by VBA. Here you have to use
-50, -100 etc.
What happens, if bal = -50 or bal = -100? Free
softdrinks for the rest af the week :-)
And what if bal = 100. I dare hardly ask :-)

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Newbie" skrev i en meddelelse
...
Hi
I want to display a message based on the value of a variable but I can't
seem to get the right 'greater than' and 'less than' signs correct for
negative numbers

It doesn't matter what the negative figure is it always goes to the last
line ie. <(100)

What am I doing wrong?

Here is what I have so far:

If bal 100 Then
msg = "Drinks are on you tonight!" & vbCrLf & "But not too many!"
ElseIf bal = 0 And bal < 100 Then
msg = "Things are looking good!"
msgstyle = vbOKOnly
ElseIf bal < 0 And bal (50) Then
msg = "Nearly there!"
msgstyle = vbOKOnly + vbExclamation

ElseIf bal < (50) And bal (100) Then
msg = "No beer for you this week!"
msgstyle = vbOKOnly + vbExclamation

ElseIf bal < (100) Then
msg = "Better ask mom and dad if you can stay for dinner!"
msgstyle = vbOKOnly + vbCritical
End If