在Excel中手动编辑依赖关系树

我有一个大的Excel电子表格。 它包含许多数据表,运行各种查找function。 为了使版本控制更容易,我目前正在将这些数据表拉出到单独的.csv文件中,以便能够正确地进行区分。 不幸的是,它们包含了一些公式,当我将该文件转换为静态.csv文件时,这显然无法正常工作。

我目前的解决scheme是,无论在哪里计算是不可避免的,将计算移动到主工作簿中的单元格,并命名单元格。 我们称之为ExampleCalc 。 然后,在计算所在数据表的单元格中,inputref:ExampleCalc 。 然后做查找,我写了下面的UDF:

 Function RaceLookup(lookupString As Variant, lookupTable As Range, raceID As Range, cleanIt As Boolean) As Variant ' Helper function to make the interface formulae neater Dim temp As Variant Dim temp2 As String Dim inpString As Variant Dim id As Double id = raceID.Value If TypeOf lookupString Is Range Then inpString = lookupString.Value Else inpString = lookupString End If With Application.WorksheetFunction temp = .Index(lookupTable, id, .Match(inpString, .Index(lookupTable, 1, 0), 0)) If Left(temp, 4) = "ref:" Then temp2 = Right(temp, Len(temp) - 4) temp = Range(temp2).Value End If If cleanIt Then temp = .clean(temp) End If End With RaceLookup = temp End Function 

这在数据表上进行标准的INDEX查找。 如果它find的入口不是以ref:开头的,它只是返回它。 如果它确实以ref:开始,则它将除去ref:并将剩下的任何内容视为单元名称引用。 所以如果INDEX返回的值是ref:ExampleCalc ,那么它将返回ExampleCalc单元格的内容。

问题是ExampleCalc不会被添加到依赖关系树中。 这意味着如果ExampleCalc的值发生变化,则检索到的值不会更新。 有什么办法让函数添加ExampleCalc到单元格的依赖树? 或者,有没有更合理的方法来做到这一点?

我find的解决scheme是添加行

 Application.Volatile True ' this causes excel to know that if the function changes, it should re calculate. You will still need to click "Calculate Now" 

进入function。 但是,正如我的代码注释所示,如果唯一的变化是在function输出中,您将不得不手动触发重新计算。

有关更多信息,请参阅https://msdn.microsoft.com/en-us/library/office/ff195441.aspx