Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Rules of Recalculation within "If x=y then Function A else Function B"

Status
Not open for further replies.

MJPPaba

MIS
May 28, 2003
142
GB
anyone know?

If you have a function as follows:
=If(A1=B1,CountA(C1:C1000000),Sum(D1:D1000000))

when excel performs a recalc does Excel recalc both the true and the false portions of the statement or is it the same as the creating your own User Definied Function and only recalcs the True or False function? I am trying to improve performance on a workbook and if I can get the functions to only recalc where necessary that will save me oodles of time.

Cheers

M

 
combo,
Why do you say a UDF is volatile? That's not my understanding, and it seems contrary to the occasional need to insert Application.Volatile in a UDF to force it to recalculate.

Brad
 
The IF formula only evaluates the third parameter if the criteria is FALSE.

To prove it, I created the following UDF:
Code:
Function test(rg As Range) As Double
MsgBox "UDF Test was called"
test = Application.Sum(rg)
End Function

I then used the following data:
A1 = 3
B1 = 3
D1:D4 =1
F1 formula =IF(A1=B1,SUM(D1:D3),TEST(D1:D4))

As I expected, the formula returned 3. But when I changed B1 to 4, I got a messagebox and then the formula returned 4.
 
byundt,
You are right, by default, UDF is not volatile.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top