ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Limit range of values for integer (https://www.excelbanter.com/excel-programming/443724-limit-range-values-integer.html)

Alan[_8_]

Limit range of values for integer
 
In VBA (used in Excel), is there a way to limit the range of values of
a variable. For example, if I want to have an integer but only have
it range from 1 - 100 in value, how would I do that.

Thanks, Alan

dksaluki

Limit range of values for integer
 
you could test for the value of the interger. something like this:

If i 0 or <=100 then
'do something here
Else
MsgBox "Please pick integer in the range of 1-100"
End If


....you could also use a SELECT....CASE block

dksaluki

Limit range of values for integer
 
correction "AND" instead of OR


If i 0 AND <=100 then
* 'do something here
Else
* *MsgBox "Please pick integer in the range of 1-100"
End If

...you could also use a SELECT....CASE block




All times are GMT +1. The time now is 06:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com