[英]Excel VBA > Formula not updating until workbook is saved
I have a very large Excel workbook (25+ worksheets, 15+ VBA modules) for financial analysis. 我有一个非常大的Excel工作簿(25个以上的工作表,15个以上的VBA模块)用于财务分析。
I've noticed that one of the formula doesn't display a value until I manually save the workbook 2 - 3 times. 我注意到,直到我手动保存工作簿2至3次,该公式之一才显示值。 Before saving it will appear as a dash (-).
在保存之前,它将显示为破折号(-)。 After saving 2 - 3 times, the values appear as expected.
保存2至3次后,值将按预期显示。
I have put in a few ActiveWorkbook.Save
in my macro runs already but they don't seem to affect this case. 我已经放了一些
ActiveWorkbook.Save
已经在我的宏运行中运行了,但是它们似乎并没有影响这种情况。
The formula in question is (for one cell): 有问题的公式是(对于一个单元格):
=OFFSET(THIS_CELL, 0, -1)+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Some Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Some Other Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))+INDEX('ExternalWorksheet'!$A$1:$CR$300,MATCH("Yet Another Term",'ExternalWorksheet'!$A:$A,0),MATCH($B5,'ExternalWorksheet'!$1:$1,0))-OFFSET(THIS_CELL, 0, -17)
(I know it is unruly, I didn't create it, I'm just the programmer ;) ) (我知道这是不守规矩的,我没有创建它,我只是程序员;)
I am using the THIS_CELL
trick as described in this other SO post because this formula appears in multiple 'tables' in this worksheet. 我正在使用另一个SO帖子中所述的
THIS_CELL
技巧,因为此公式出现在此工作表的多个“表”中。
My client isn't pleased about having this column appear as dashes and the columns that depend on it appearing as N/A until he saves. 我的客户不满意让该列显示为破折号,而依赖该列的列显示为N / A,直到他保存为止。 From what I can tell, this behaviour is related to the usage of THIS_CELL (or the OFFSET) as if I remove the OFFSET the cells update as expected.
据我所知,此行为与THIS_CELL(或OFFSET)的使用有关,就好像我删除了单元格按预期更新的OFFSET一样。 However, I can't see how to get rid of it as I have to repeat this formula over multiple 'tables' in the worksheet and have them reference the correct cells.
但是,我看不到如何摆脱它,因为我必须在工作表中的多个“表”上重复此公式,并让它们引用正确的单元格。 I also can't switch to RC notation as my client doesn't like it.
我也不能切换到RC表示法,因为我的客户不喜欢它。
You can modify THIS_CELL trickery to remove dependency on the OFFSET
function altogether by changing the initial selected cell to produce the offset necessary. 您可以通过更改初始选定的单元格以产生必要的偏移量来修改THIS_CELL技巧,以完全消除对
OFFSET
函数的依赖。 The reason that the first step in those directions states select cell A1 (this is important!) is so THIS_CELL always refers to the cell you selected. 在这些方向上第一步说明选择单元格A1的原因(这很重要!) ,因此THIS_CELL始终引用您选择的单元格。 You don't want the cell that you selected.
您不需要所选的单元格。 You want the one either 1 or 17 columns to the left.
您想要左边的1列或17列。
(stolen and modified from Create a named formula called THIS_CELL ) (从创建名为THIS_CELL的命名公式窃取并修改)
=!Q1
=!Q1
NOTE: Be sure cell R1 is selected. 注意:确保已选择单元格R1 。 This formula is relative to the ActiveCell.
此公式相对于ActiveCell。
Under Scope: select Workbook. 在范围下:选择工作簿。
Click OK. 单击确定。
Repeat using the name THE_CELL_WAY_BEHIND_ME and =!A1
for refers to. 重复使用名称THE_CELL_WAY_BEHIND_ME和
=!A1
作为引用。
Close the Name Manager. 关闭名称管理器。
Using =THE_CELL_BEHIND_ME
is the same as =OFFSET(THIS_CELL, 0, -1)
and =THE_CELL_WAY_BEHIND_ME
is the same as =OFFSET(THIS_CELL, 0, -17)
. 使用
=THE_CELL_BEHIND_ME
与=OFFSET(THIS_CELL, 0, -1)
相同,并且=THE_CELL_WAY_BEHIND_ME
与=OFFSET(THIS_CELL, 0, -17)
。
I did a comparsion between CTRL+S save and a ActiveWorkbook.Save
and in this case they do work differently. 我在CTRL + S保存和
ActiveWorkbook.Save
,在这种情况下,它们的工作方式有所不同。 No matter how many times I save via VBA it wouldn't update the formulae. 无论我通过VBA保存多少次,都不会更新公式。 CTRL+S appears to be forcing a re-calculation.
CTRL + S似乎正在强制重新计算。
From this post I added in 在这篇文章中,我添加了
ActiveSheet.EnableCalculation = False
ActiveSheet.EnableCalculation = True
prior to saving and that has solved the problem. 在保存之前已经解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.