View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Comparing negative number

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

ElseIf bal -100 Then
msg = "No beer for you this week!"
msgstyle = vbOKOnly + vbExclamation

Else
msg = "Better ask mom and dad if you can stay for dinner!"
msgstyle = vbOKOnly + vbCritical
End If
Else
msgbox "Bal isn't a number"
End if


Since your checks are progressive, there is no need to put in two conditions
(50) is +50. Use a minus sign to make refer to a negative number.

--
Regards,
Tom Ogilvy


"Newbie" wrote in message
...
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