Referencing Public Constants in Cell Formulas

早过忘川 提交于 2019-12-13 04:33:39

问题


I would like to be able reference a public constant in a cell formula. I have found multiple references to defining constants from cell values, but not for using constants in formulas.

I would like to be able do something like this (I know that this is not the right syntax, but you get the idea...)

="Some formula text " & myPublicConstantName

Ideas?

Thank!


回答1:


Your public constant lives in a standard module, and probably looks something like this:

Public Const Foo As Long = 42

You can expose it through a UDF:

Public Function GetFoo() As Long
    GetFoo = Foo
End Function

And now you can have ="some formula text " & GetFoo() in a worksheet cell.




回答2:


I'm confused what you mean by "I have found multiple references to defining constants from cell values." I think you're looking for a VBA solution (?), but just in case you're not, you can just define a name and you're good to go:



来源:https://stackoverflow.com/questions/56465548/referencing-public-constants-in-cell-formulas

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