Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Excel VBA Function Results

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.

like image 472
Brian Sullivan Avatar asked Aug 14 '08 13:08

Brian Sullivan


People also ask

How do you refresh a VBA function in Excel?

You can trigger a data refresh when your Excel file is first opened by pasting VBA code into the Workbook_Open event. Simply double-click the ThisWorkbook object in the VBA Project Pane to open the text editor (blank white sheet) within the Visual Basic Editor (keyboard shortcut Alt +F11).

How do I refresh all connections in VBA?

You can also press Ctrl+Alt+F5 anywhere in the workbook. This command not only refreshes data connections, it also refreshes all pivot tables (which are a form of data connection).

How do I recalculate all formulas in Excel?

The keyboard shortcut for that choice is Shift + F9 . Recalculate formulas that have changed since the last calculation, and formulas dependent on them, in all open workbooks. If a workbook is set for automatic recalculation, you do not need to press F9 for recalculation.


2 Answers

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).

like image 96
vzczc Avatar answered Sep 30 '22 07:09

vzczc


Some more information on the F9 keyboard shortcuts for calculation in Excel

  • F9 Recalculates all worksheets in all open workbooks
  • Shift+ F9 Recalculates the active worksheet
  • Ctrl+Alt+ F9 Recalculates all worksheets in all open workbooks (Full recalculation)
  • Shift + Ctrl+Alt+ F9 Rebuilds the dependency tree and does a full recalculation
like image 44
Robert Mearns Avatar answered Sep 30 '22 09:09

Robert Mearns