Hi to all . I want to write a statement with an " if " between two numbers , how can it be done? eg If 150 between 100 and 200 then ... "do something" end if
Regards
Printable View
Hi to all . I want to write a statement with an " if " between two numbers , how can it be done? eg If 150 between 100 and 200 then ... "do something" end if
Regards
In A1: 30
In A2:200
In A3:100
PHP Code:
=INT(A1/(A2-A3))=0
Hi thank you for your answer but i don't understant , how can i use this in the VBA code , what i want is how to syntax the "if" statement
or on one line:Code:If number1 >100 and number1 < 200 then
'...do whatever you want done
End If
where number1 is a variable containing your number (150 in your example).Code:If number1 >100 and number1 < 200 then '...do something
PHP Code:
Sub M_snb()
x = 99
y = 200
Z = 100
If Int((x - Z) / (y - Z)) = 0 Then MsgBox x & " lies between " & Z & " and " & y
End Sub
OK Thank you
Personal style
1. I find it's better if I use parentheses to group each part of the AND
2. I like to arrange the conditionals is what to me is a logical order based on the way I think
L <= N <= H
3. I don't see any reason to squeeze everything onto one line since I find it can make things harder to read
Just seems to make it easier for me
Code:
Sub test()
Dim n As Long, L As Long, H As Long
n = 150
L = 100
H = 200
If (L <= n) And (n < H) Then
MsgBox n & " is between " & L & " and " & H
Else
MsgBox "nope"
End If
End Sub
If you had to do a lot, you could make a boolean function. It's simple, but might make it easier to follow the logic. Probably costs a few insignificant CPU cycles
Code:Sub test2()
Dim N As Long, L As Long, H As Long
N = 150
L = 100
H = 200
If Between(L, N, H) Then
'Do Something
End If
End Sub
Function Between(L As Variant, N As Variant, H As Variant) As Boolean
Between = (L <= N) And (N < H)
End Function