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
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
Last edited by ksilenio; 11-12-2019 at 02:14 PM.
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: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).If number1 >100 and number1 < 200 then '...do something
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
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
Last edited by snb; 11-13-2019 at 03:31 AM.
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
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
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
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3