通过VBA在Excel Listobject / Table中添加/修改/删除计算列公式 [英] Add/Modify/delete calculated column formula in Excel Listobject/Table via VBA

查看:1345
本文介绍了通过VBA在Excel Listobject / Table中添加/修改/删除计算列公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Excel表(即ListObject)中的列中手动输入公式,则自动更正将此公式应用于整列。

If I manually enter a formula into a column in an Excel table (i.e. ListObject), AutoCorrect applies this formula to the whole column.

有没有办法我可以通过VBA控制这种行为,也就是说我可以修改/删除/添加这个公式吗?

Is there any way to control the this behavior via VBA, i.e. can I somehow modify/delete/add this formula?

我知道我可以简单的改变 ListObject.ListColumns(1).DataBodyRange 对象 - 但这将覆盖之前输入的任何手动值 - 在更改UI中的公式时,将保持不变...

I know I can simply change the formula of the ListObject.ListColumns(1).DataBodyRange object - but this will overwrite any manually values entered before - while changing the formula in the UI will leave this untouched...

推荐答案

感谢Doug's和bonCodigos的评论/答案,我找到了简单的答案:

Thanks to Doug's and bonCodigos comments/answers, I found the simple answer:

ListObject.ListColumns("Column name").DataBodyRange.FormulaR1C1 = "new formula"

这将覆盖任何手动值(与自动更正的正常行为一样)。

This will overwrite any manual value (just as the normal behavior with AutoCorrect).

这篇关于通过VBA在Excel Listobject / Table中添加/修改/删除计算列公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆