View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Between to values


Some alternatives:

Function TempIt(ByVal Temp%) As Integer
TempIt = Application.Lookup(Temp, _
Array(-1E+99, 10, 15, 20, 25), _
Array(5, 4, 3, 2, 1))
End Function

Function TempIt2(ByVal Temp%) As Integer
Dim iRes%
Select Case Temp
Case Is < 10: iRes = 5
Case Is < 15: iRes = 4
Case Is < 20: iRes = 3
Case Is < 25: iRes = 2
Case Else: iRes = 1
End Select
TempIt2 = iRes
End Function

Function TempIt3(ByVal Temp%) As Integer
Dim iRes%
If Temp < 10 Then
iRes = 5
ElseIf Temp < 15 Then
iRes = 4
ElseIf Temp < 20 Then
iRes = 3
ElseIf Temp < 25 Then
iRes = 2
Else
iRes = 1
End If
TempIt3 = iRes
End Function



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


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?