Barb,
A UDF will recalculate only when one of its precedent (input) cells is
changed. For this reason, you should always pass in any cell reference and
never address cells directly from the VBA code. For example,
' Do This
Function XYZ(Rng1 As Range, Rng2 As Range) As Double
' your code
XYZ = Rng1.Value + Rng2.Value
End Function
' Do NOT Do This
Function XYZ(Rng1 As Range)
Dim Rng2 As Range
Set Rng2 = Range("A1")
XYZ = Rng1.Value + Rng2.Value
End Function
In the second example, Excel can't know that XYZ uses cell A1, and thus will
not recalculate when A1 is changed.
You can include Application.Volatile True to cause VBA to calculate the
function whenever any calculation is performed, not just when a precedent is
changed. E.g,
Function XYZ(Rng1 As Range)
Application.Volatile True
' your code
End Function
Note, though, that Volatile may cause sluggish performance.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)