Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Excel to refresh data on sheet from within VBA

Tags:

excel

vba

How do you get spreadsheet data in Excel to recalculate itself from within VBA, without the kluge of just changing a cell value?

like image 819
Lance Roberts Avatar asked Sep 30 '08 18:09

Lance Roberts


People also ask

How do I automatically update data from another sheet in Excel?

Automatically refresh data at regular intervals Click a cell in the external data range. On the Data tab, in the Connections group, click Refresh All, and then click Connection Properties. Click the Usage tab. Select the Refresh every check box, and then enter the number of minutes between each refresh operation.

How do you refresh data 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 you refresh cells in Excel VBA?

VBA code: Only recalculate selected cells in ExcelPress the F5 key to run the code, then the selected formula cells are recalculated immediately.


1 Answers

The following lines will do the trick:

ActiveSheet.EnableCalculation = False   ActiveSheet.EnableCalculation = True   

Edit: The .Calculate() method will not work for all functions. I tested it on a sheet with add-in array functions. The production sheet I'm using is complex enough that I don't want to test the .CalculateFull() method, but it may work.

like image 109
Lance Roberts Avatar answered Oct 05 '22 21:10

Lance Roberts