Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test 2 numbers Dave Excel Worksheet Functions 18 February 7th 09 09:03 PM
Converting test to numbers and adding into a summary page Laura Excel Worksheet Functions 1 September 7th 06 04:24 PM
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
logical test, array, text and numbers Dan M. Excel Worksheet Functions 1 April 25th 06 08:56 AM
Test cells within Range("S16:S19) are NOT Numbers CRayF Excel Programming 3 September 27th 05 01:50 PM


All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"