View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta Tushar Mehta is offline
external usenet poster
 
Posts: 1,071
Default Nesting limits in VBA

Hi Tom,

My comment was not aimed at your suggestion. It was targeted at how
one might eliminate a (one-sided) bushy tree.

If i <= 3 then
If i <= 2 then
If i <= 1 then
msgbox "i <= 1"
else
msgbox "i=2"
end if
else
msgbox "i=3"
end if
else
msgbox "i 3"
end if

could be replaced with

if i 3 then
msgbox "i 3"
elseif i =3 then
msgbox "i =3"
elseif i=2 then
msgbox "i=2"
else
msgbox "i <=1"
end if

or, of course, with a case statement.

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Maybe I should have used the generic

If criteria1 and criteria2 and criteria3 and criteria4 then


End if

--
Regards,
Tom Ogilvy

Tushar Mehta wrote in message
om...
Hi Tom,

In article ,

says...
how to make it flatter would depend on the criteria - if they don't have

to
checked sequentially, then use the And statement

if 1< i and 2 < i and 3 < i and 4 < i and 5 < i and 6 < i then

end if

as an example.


Alternatively, just reverse the tests...

If i15 then
ElseIf i 14 then
ElseIf i 13 then
...
elseif i1 then
else
end if
--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions