如何更改单元格的值(显示文本)而不更改其公式? [英] How to VBA change cell's value (display text) without changing its formula?
问题描述
Sub demoChangeText()
Application.Range( B2)Value =Override text
End Sub
我的测试是 here 。要运行此宏,请在Excel中打开它,按 Ctrl + F8
并选择 demoChangeText
。
因此,此宏会更改单元格 B2
(显示给我们的文本)的值,但要清除其公式。我需要更改 B2
的值,但也需要保留公式。
所以我的问题是如何更改单元格的显示文本而不更改其公式?
更新
我问这个问题是因为我试图解决这个问题
我不知道这是否有帮助,因为这有点难告诉你的基本要求是什么,但是这里反过来:
几个事情影响单元格的显示:
- 输入的值,如果它的一个常数
- 计算的结果,如果它的公式
- 单元格的格式
- 单元格的条件格式(如果有)
在提供的示例表中,您有一个公式为 = ROW()& COLUMN()
返回字符串结果 22
您可以使这个显示通过应用单元格格式的其他东西, 这可以通过应用VBA与 或 I've a problem with this VBA macro. My test is here. To run this macro, open it in Excel, press As the result, this macro changes the value of cell So my question is How to change the display text of cell without changing its formula? UPDATE I ask this question because I'm trying to solve this problem I'm not sure if this will help, as it is a bit hard to tell what your underlying requirement is, but here goes anyway: Several things affect the display of a cell: In the example sheet provided you have a formula of You can make this display something else by applying a cell format, This can by applied with VBA with or
这篇关于如何更改单元格的值(显示文本)而不更改其公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
,例如格式为 0; 0; 0; Ov\e\r\ri\d\d\ e \\\\\\\\\\\\\\\\\,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Range(B2)。NumberFormat =0; 0; 0; Ov\e\r\ri\d\d\e\\\
t\ext\s
范围(B2)。NumberFormat =0; 0 ; 0;覆盖文本
Sub demoChangeText()
Application.Range("B2").Value = "Overidden text"
End Sub
Ctrl+F8
and choose demoChangeText
.B2
(the text displayed to us) but clear its formula. I need to change B2
's value BUT also need the formula to be remained.
=ROW()&COLUMN()
which returns a string result of 22
eg a format of 0;0;0;Ov\e\r\ri\d\d\e\n t\ext
will display any string value as Overridden text
Range("B2").NumberFormat = "0;0;0;Ov\e\r\ri\d\d\e\n t\ext\s"
Range("B2").NumberFormat = "0;0;0;""Overridden texts"""