问题
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