How to VBA change cell's value (display text) without changing its formula?

跟風遠走 提交于 2019-12-01 04:02:18
chris neilsen

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:

  1. the entered value, if its a constant
  2. the result of a calculation, if its a formula
  3. the format of the cell
  4. the conditional format(s) of the cell, if any

In the example sheet provided you have a formula of =ROW()&COLUMN() which returns a string result of 22

You can make this display something else by applying a cell format,
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

This can by applied with VBA with

Range("B2").NumberFormat = "0;0;0;Ov\e\r\ri\d\d\e\n t\ext\s"

or

Range("B2").NumberFormat = "0;0;0;""Overridden texts"""
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!