tags:

views:

12022

answers:

3

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

+1  A: 

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 I don't want to try and test the .CalculateFull() method, so it may work.

Lance Roberts
Actually, there are .Calculate() and .CalculateFull() methods for that, on different levels.
GSerg
I've tested Calculate on a sheet, and it not all functions in a cell recalculate. You can also do it by switching the 'dirty' bit, but I found this to be the easiest solution.
Lance Roberts
A: 

This should do the trick...

'recalculate all open workbooks
Application.Calculate

'recalculate a specific worksheet
Worksheet(1).Calculate

' recalculate a specific range
Worksheet(1).Columns(1).Calculate
Graham Miller
see comment on my answer
Lance Roberts
A: 

You might also try

Application.CalculateFull

or

Application.CalculateFullRebuild

if you don't mind rebuilding all open workbooks, rather than just the active worksheet. (CalculateFullRebuild rebuilds dependencies as well.)

Dave DuPlantis