Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Does an if statement calculate both the true and false?

I have a spreasheet, with 40000+ rows.
I have an if statement which is basically if(A1="OK",0,long and complex
formula).
Almost all instances are "OK" with a few exceptions requiring the complex,
time consuming part of the formula.
Does excel calculate that part of the formula even for cells which are "OK"
and hence taking up loads of time, or does it ignore it knowing it doesn't
need to return it?
Thanks!
Chris
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Does an if statement calculate both the true and false?

Hi,


VBA evaluates both parts of the formula, the Excel worksheet IF function
only evaluates one part of the formula depending on whether the logical
condition is TRUE or FALSE


Tushar Mehta has an excellent tutorial on the IF function here

http://www.tushar-mehta.com/publish_...f_function.htm


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"chriswilko" wrote:

I have a spreasheet, with 40000+ rows.
I have an if statement which is basically if(A1="OK",0,long and complex
formula).
Almost all instances are "OK" with a few exceptions requiring the complex,
time consuming part of the formula.
Does excel calculate that part of the formula even for cells which are "OK"
and hence taking up loads of time, or does it ignore it knowing it doesn't
need to return it?
Thanks!
Chris

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Does an if statement calculate both the true and false?

Excel does not appear to calculate the false part if the true part is valid.
I tried the formula:

=IF(A1<0,0,trial(A1))
where trial is the UDF:

Function trial(r As Range) As Double
For i = 1 To 1000000
trial = trial + r.Value
Next
trial = trial + 1
End Function

I tried several numbers in A1 and the result was instantaneous unless I
entered 0
--
Gary''s Student - gsnu201001


"chriswilko" wrote:

I have a spreasheet, with 40000+ rows.
I have an if statement which is basically if(A1="OK",0,long and complex
formula).
Almost all instances are "OK" with a few exceptions requiring the complex,
time consuming part of the formula.
Does excel calculate that part of the formula even for cells which are "OK"
and hence taking up loads of time, or does it ignore it knowing it doesn't
need to return it?
Thanks!
Chris

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default Does an if statement calculate both the true and false?

On Mar 31, 5:13*pm, chriswilko
wrote:
I have a spreasheet, with 40000+ rows.
I have an if statement which is basically if(A1="OK",0,long and complex
formula).
Almost all instances are "OK" with a few exceptions requiring the complex,
time consuming part of the formula.
Does excel calculate that part of the formula even for cells which are "OK"
and hence taking up loads of time, or does it ignore it knowing it doesn't
need to return it?
Thanks!
Chris


Hi Chris,

If the value is "OK", it will check for the TRUE value and exit the
function... so no need to worry about the complex satement incase the
value is "OK"

Ratheesh
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 905
Default Does an if statement calculate both the true and false?

"chriswilko" wrote:
I have an if statement which is basically
if(A1="OK",0,long and complex formula).

[....]
Does excel calculate that part of the formula
even for cells which are "OK" and hence taking
up loads of time, or does it ignore it knowing it
doesn't need to return it?


Unlike a real function, the IF expression evaluates only the parts that are
necessary; at least, in Excel 2003. You can validate that fact for your
revision of Excel with the following.

=if(A1,myUDF(1),myUDF(2))

where A1 is a 0 or 1, and myUDF is:

Function myUDF(x)
myUDF = x
MsgBox "myUDF " & x
End Function


----- original message -----

"chriswilko" wrote:
I have a spreasheet, with 40000+ rows.
I have an if statement which is basically if(A1="OK",0,long and complex
formula).
Almost all instances are "OK" with a few exceptions requiring the complex,
time consuming part of the formula.
Does excel calculate that part of the formula even for cells which are "OK"
and hence taking up loads of time, or does it ignore it knowing it doesn't
need to return it?
Thanks!
Chris

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TRUE/FALSE STATEMENT Dave Excel Discussion (Misc queries) 4 September 1st 09 11:55 AM
TRUE/FALSE function in IF statement Caelan Aegana Excel Worksheet Functions 2 July 21st 08 11:45 PM
Two TRUE to one FALSE statement bluebird Excel Worksheet Functions 4 January 11th 07 04:07 PM
If Statement returns true when false? Eric Excel Discussion (Misc queries) 3 September 11th 06 01:58 PM
How can I make a True or False statement a certain color when usi. Wendy Excel Worksheet Functions 1 January 28th 05 05:55 PM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"