View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Between to values

VBA evaluates your conditions in order and takes the first one that is True.
17 satisfies the condition "ElseIf TemperaturInput 10 Or TemperaturInput <
15" (because it is greater than 10) so VBA applies the result PoFResult = 4
and then figures it is done evaluating your If statement. Actually, I think
you really meant to say "AND" where you have your "OR"s, but it is still
problematic - for one thing, if you have a TemperaturInput exactly equal to
10, 15, 20, or 25 you will not get any value for PoFResult.

There are many ways to do this, but you could simplify it quite a bit if you
do it like this:
PoFResult = 5
If TemperaturInput 10 Then PoFResult = 4
If TemperaturInput 15 Then PoFResult = 3
If TemperaturInput 20 Then PoFResult = 2
If TemperaturInput 25 Then PoFResult = 1

--
- K Dales


"Michael" wrote:

Hi!
I have a VB formula that look like this.

TemperaturInput=FrmSeawaterParameter25CrSDSS.TxtTe mperature.Value

If TemperaturInput < 10 Then
PoFResult = 5
ElseIf TemperaturInput 10 Or TemperaturInput < 15 Then
PoFResult = 4
ElseIf TemperaturInput 15 Or TemperaturInput < 20 Then
PoFResult = 3
ElseIf TemperaturInput 20 Or TemperaturInput < 25 Then
PoFResult = 2
ElseIf TemperaturInput 25 Then
PoFResult = 1
End If

My problem is that this is not correct, if a set TemperaturInput=17 on this
i will get
PoFResult =4 and that is NOT correct!

What is wrong?