vba 如何在excel中即时刷新计算
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31959317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh calculation instantaneously in excel
提问by Souma
I have a problem in refreshing the cell's calculation.
我在刷新单元格的计算时遇到问题。
In other words, I have many columns where i have a formula or macro in each one of them.
换句话说,我有很多列,其中每一列都有一个公式或宏。
But the problem is that i should absolutely activate the option " automatic calculation" in the excel options or i should save then the new results appear.
但问题是我应该绝对激活excel选项中的“自动计算”选项,或者我应该保存然后新结果出现。
Now, I would insert something in the macro that can refresh me the results instantaneously.
现在,我会在宏中插入一些可以立即刷新结果的内容。
Thanks
谢谢
回答by R3uK
You could simply press :
你可以简单地按:
F9to calculate the whole active workbook
F9计算整个活动工作簿
Shift + F9to calculate the active sheet
Shift + F9计算活动表
Anyway, here are the different options with .Calculate:
无论如何,这里有不同的选项.Calculate:
Sub Souma()
'Use this to calculate all the open workbooks
Application.Calculate
'Use this to calculate the whole sheet, called "Sheet1"
ThisWorkbook.Worksheets("Sheet1").Calculate
'Use this to calculate the cell A1 on the sheet called "Sheet1"
ThisWorkbook.Worksheets("Sheet1").Range("A1").Calculate
'Use this to calculate the range A1 to D10 on the sheet called "Sheet1"
ThisWorkbook.Worksheets("Sheet1").Range("A1:D10").Calculate
'Use this to calculate the column A on the sheet called "Sheet1"
ThisWorkbook.Worksheets("Sheet1").Columns(1).Calculate
'Use this to calculate the row 1 on the sheet called "Sheet1"
ThisWorkbook.Worksheets("Sheet1").Rows(1).Calculate
End Sub
回答by Paulo
Copy and paste the code below to your VBA project:
将下面的代码复制并粘贴到您的 VBA 项目中:
Private Sub Workbook_Open()
Application.Calculation = xlCalculationAutomatic
End Sub
This code should automatically run after you open the Excel file, enabling automatic calculation in allopened files.
此代码应在您打开 Excel 文件后自动运行,从而在所有打开的文件中启用自动计算。
回答by Spere
To force all formulas to update, including custom vba formulas, execute the following in VBA:
要强制更新所有公式,包括自定义 vba 公式,请在 VBA 中执行以下操作:
Application.CalculateFullRebuild
This can also be executed from the VBA immediate window.
这也可以从 VBA 立即窗口执行。
More documentation here: https://docs.microsoft.com/en-us/office/vba/api/excel.application.calculatefullrebuild
更多文档在这里:https: //docs.microsoft.com/en-us/office/vba/api/excel.application.calculatefullrebuild

