Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if value is between two numbers
What's the code to test if a value is between two numbers? I can easil find the answer for other languages, but not VBA! TIA -- smplog ----------------------------------------------------------------------- smplogc's Profile: http://www.excelforum.com/member.php...fo&userid=3388 View this thread: http://www.excelforum.com/showthread.php?threadid=53760 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if value is between two numbers
smplogc Wrote: What's the code to test if a value is between two numbers? I can easily find the answer for other languages, but not VBA! TIA. Sub testvalue() If Selection.Value = 5 Then If Selection.Value <= 10 Then Selection.Offset(1, 0).Value = 25 'this is where you can put your code End If End If End Sub there are dozens of of sites that explain VBA, here is a great one to start printing off and start reading http://www.mindspring.com/~tflynn/ex...html#Send_Mail http://www.excel-vba.com/index.htm -- davesexcel ------------------------------------------------------------------------ davesexcel's Profile: http://www.excelforum.com/member.php...o&userid=31708 View this thread: http://www.excelforum.com/showthread...hreadid=537603 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if value is between two numbers
This expression
Sgn(No1-YourNum) + Sgn(No2-YourNum) enumerates all 5 possibilities: Your number less than the minimum of No1, No2 Your number is equal to the minimum of No1, No2 Your numer is between No1 & No2 Your number is equal to the maximum of No1, No2 Your number greater than the maximum of No1, No2 "smplogc" wrote: What's the code to test if a value is between two numbers? I can easily find the answer for other languages, but not VBA! TIA. -- smplogc ------------------------------------------------------------------------ smplogc's Profile: http://www.excelforum.com/member.php...o&userid=33887 View this thread: http://www.excelforum.com/showthread...hreadid=537603 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if value is between two numbers
The example test whether a number is between 50 and 100. It first assigns the
value to be tested to a variable "a". In the example, the value of the selected cell is being tested. Sub test() Dim a a = Selection.Value If a 50 And a < 100 Then MsgBox "Hello" End If End Sub Regards, Edwin Tam http://www.vonixx.com "smplogc" wrote: What's the code to test if a value is between two numbers? I can easily find the answer for other languages, but not VBA! TIA. -- smplogc ------------------------------------------------------------------------ smplogc's Profile: http://www.excelforum.com/member.php...o&userid=33887 View this thread: http://www.excelforum.com/showthread...hreadid=537603 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if value is between two numbers
Just to add one more
Dim nMax as Long, nMin as Long, MyNum as Long nMax = 51 nMin = 39 MyNum = int(rnd()*100+1) if MyNum nMin and MyNum < nMax then end if -- Regards, Tom Ogilvy "smplogc" wrote in message ... What's the code to test if a value is between two numbers? I can easily find the answer for other languages, but not VBA! TIA. -- smplogc ------------------------------------------------------------------------ smplogc's Profile: http://www.excelforum.com/member.php...o&userid=33887 View this thread: http://www.excelforum.com/showthread...hreadid=537603 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Test 2 numbers | Excel Worksheet Functions | |||
Converting test to numbers and adding into a summary page | Excel Worksheet Functions | |||
Calculate mean of test scores from rows of test answers | Excel Discussion (Misc queries) | |||
logical test, array, text and numbers | Excel Worksheet Functions | |||
Test cells within Range("S16:S19) are NOT Numbers | Excel Programming |