如何在当前单元格中添加文本而不会产生循环引用错误。

huangapple go评论91阅读模式
英文:

How to add text in current cell without creating the circular reference error

问题

我试图在当前选定的单元格中添加文本

我的VBA函数是:

Function AddText()
    ActiveCell.Value = "Hello World!"
End Function

但当我调用该函数时,我收到以下错误消息:

"存在一个或多个循环引用,其中一个公式直接或间接地引用了自己的单元格。这可能会导致它们计算不正确。尝试删除或更改这些引用,或将公式移动到不同的单元格。"

请帮忙!

英文:

I'm trying to add text in the current selected cell

My VBA function is :

Function AddText()
    ActiveCell.Value = "Hello World!"
End Function

But I'm getting following error when I call the function :

"There are one or more circular references where a formula refers to its own cell either directly or indirectly. This might cause them to calculate incorrectly. Try removing or changing these references, or moving the formulas to different cells."

Please help!

答案1

得分: 1

使用函数时,您需要让函数返回值,而不是更改单元格的值:

Function AddText()
    AddText = "Hello World!"
End Function

然后,您可以在单元格中像这样使用它
=AddText()
这将在您键入它的单元格中显示 "Hello World!"。

英文:

When using a function, you need to let the function return the value, not change the cell's value:

Function AddText()
    AddText = "Hello World!"
End Function

and then you can use it in a cell like so
=AddText()
which will show "Hello World!" in the cell you've typed it in.

huangapple
  • 本文由 发表于 2023年5月31日 22:58:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76374847.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定