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
2008-09-30 18:54:58
Actually, there are .Calculate() and .CalculateFull() methods for that, on different levels.
GSerg
2008-09-30 19:15:47
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
2008-09-30 19:26:41
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
2008-09-30 19:26:59
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
2008-09-30 19:52:04