VBA check to see if variable value is odd but not equal to 1
Or with not that many lines, but basically the same:
dim myVal as variant
myval =
workbooks("someworkbook.xls").worksheet("somesheet ").range("x99").value
if isnumeric(myval) AND myval < 1AND myval mod 2 = 1 then
'do your stuff here, like:
msgbox myval
end if
unless you need to find out which statement did fail you can use the
short form.
hth
Carlo
On Nov 21, 7:26 am, Dave Peterson wrote:
dim myVal as variant
myval = workbooks("someworkbook.xls").worksheet("somesheet ").range("x99").value
'is it a number
if isnumeric(myval) then
'is it different from 1
if myval < 1 then
'is it a whole number
if myval = int(myval) then
if (myval/2) < int(myval/2) then
'it's odd
'do your stuff here, like:
msgbox myval
end if
end if
end if
end if
Dave L wrote:
I need to run a subroutine based on a variable value. I'm sure it'll be an if
statement, but how do I tell something not to run if a specific variable's
value is an odd number but not equal to 1.
--
Dave Peterson
|