Refresh Excel VBA Function Results

Brian Sullivan picture Brian Sullivan · Aug 14, 2008 · Viewed 144.4k times · Source

How can I get a user-defined function to re-evaluate itself based on changed data in the spreadsheet?

I tried F9 and Shift+F9.

The only thing that seems to work is editing the cell with the function call and then pressing Enter.

Answer

vzczc picture vzczc · Aug 15, 2008

You should use Application.Volatile in the top of your function:

Function doubleMe(d)
    Application.Volatile
    doubleMe = d * 2
End Function

It will then reevaluate whenever the workbook changes (if your calculation is set to automatic).