ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What is quicker? Nested or non nested ifs (https://www.excelbanter.com/excel-programming/292520-what-quicker-nested-non-nested-ifs.html)

andycharger[_17_]

What is quicker? Nested or non nested ifs
 
I have a set of conditions on my macro.

If it is one type, set the color background to "whatever"
Then go on to the next if statement and do that colour.

Im wondering if there is much of a performance gain over nesting the I
statements or not? Would it take the same amount of time to run?

IE

If then
else
end if

If then
Else
end if

if then
Else
End if

or
If then
else
if
else
if
else
end if
end if
end if


Any ideas

--
Message posted from http://www.ExcelForum.com


Michael J. Malinsky

What is quicker? Nested or non nested ifs
 
I've never really experimented with one way over the other. I just go with
whatever seems more logical at the time. I asked about performance of
macros on this forum before and the general consensus is that there are
sometimes several ways to accomplish the same thing in VBA. Trying to find
the "fastest" probably won't make a noticable difference in the time it
takes for the macro to run.

I was once told that as long as the code does what you want it to do and
doesn't do what you don't want it to do, then you should just run with it.

Mike.


--
Michael J. Malinsky


"andycharger " wrote in message
...
I have a set of conditions on my macro.

If it is one type, set the color background to "whatever"
Then go on to the next if statement and do that colour.

Im wondering if there is much of a performance gain over nesting the IF
statements or not? Would it take the same amount of time to run?

IE

If then
else
end if

If then
Else
end if

if then
Else
End if

or
If then
else
if
else
if
else
end if
end if
end if


Any ideas?


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

What is quicker? Nested or non nested ifs
 
Andy,

The problem with former way is that is every IF test is evaluated, even
after one has matched. The latter avoids this, so on the basis of
probability, it is more efficient. Also, it reads better IMO.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"andycharger " wrote in message
...
I have a set of conditions on my macro.

If it is one type, set the color background to "whatever"
Then go on to the next if statement and do that colour.

Im wondering if there is much of a performance gain over nesting the IF
statements or not? Would it take the same amount of time to run?

IE

If then
else
end if

If then
Else
end if

if then
Else
End if

or
If then
else
if
else
if
else
end if
end if
end if


Any ideas?


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:48 PM.

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