Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I read the OP's request as NOT wanting something to run if the
variable's value was odd but not equal to 1, i.e. he DOES want it to run if equal to 1 or even. I think you (and Dave) have the logic the wrong way round. Pete On Nov 21, 12:58 am, carlo wrote: 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- Hide quoted text - - Show quoted text - |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Could be. Or maybe not. <bg.
That's why I like to use parens in my code (and in text!). Does Not A And B mean (not A) and B or Not (A and B) Pete_UK wrote: I read the OP's request as NOT wanting something to run if the variable's value was odd but not equal to 1, i.e. he DOES want it to run if equal to 1 or even. I think you (and Dave) have the logic the wrong way round. Pete On Nov 21, 12:58 am, carlo wrote: 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- Hide quoted text - - Show quoted text - -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
can I make cell "yes" equal 1, "no" equal 0 | Excel Discussion (Misc queries) | |||
Sum cells based on a row variable and seperate column variable | Excel Worksheet Functions | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions | |||
check if 2 cells are equal but only if they contain numbers not i. | Excel Worksheet Functions | |||
check if 2 cells are equal but only if they contain numbers not i. | Excel Worksheet Functions |