Thread
:
Better way for writing IF statement ?
View Single Post
#
10
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
Better way for writing IF statement ?
See my post. The WORKSHEET limit for nested if's is 7 but there are several
workarounds. However, it is best then to use a lookup table or another
method.
If you would fully explain your problem perhaps someone could be able to
help. No mind reading here
--
Don Guillett
SalesAid Software
"monir" wrote in message
...
macropod;
Sorry, I misspoke! The limit of max 9 IFs is for the nested w/s IF
function.
My apologies!
"macropod" wrote:
Hi monir,
Why do you think you're limited to 9 nested IFs? There's a worksheet
limit
of 7, but that doesn't apply to vba. I just ran a test with 12 nested vba
IFs in both Word and Excel and got the expected result with no complaint
from vba about any limits being exceeded.
Cheers
--
macropod
[MVP - Microsoft Word]
"monir" wrote in message
...
Hi;
Since it's the same variable myVar1 that I'm testing, I thought there
might
be a way (documented or improvised) that could be applied in this
situation.
Something like inserting: "." or " ," or ":=" or "/" or whatever!
I originally had a nested IF similar to yours, but realized then that
one
is limited to a max of 9 tested conditions within the nested IF
(ocassionally. there're more conditions!). So, I switched to a
single-line
IF, where applicable, regardless of the number of conditions.
In some situations, the nested IF is the preferable (if not the only)
way
to
do the tests, where for each satisfied condition(s), there're different
computational procedures to follow.
Back to my sample:
IF myVar1 = 1 And myVar1 < 100 And myVar1 < 25 And myVar1 <= Index
Then
GoTo myLable
How about
:
Select Case myVar1
Case = 1, < 100, < 25, <= Index
GoTo myLable
End Select
with the above commas (which represent OR) are replaced by AND (or
something
equivelant) ?? I've done a dry run. It didn't work.
Regards.
"tony h" wrote:
Macropod is quite right but I wondered, Monir, whether there is more
behind the question. EG are you having to repeat this lots of times?
If
so post some more description of the issue
Cheers
--
tony h
------------------------------------------------------------------------
tony h's Profile:
http://www.excelforum.com/member.php...o&userid=21074
View this thread:
http://www.excelforum.com/showthread...hreadid=548020
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett