英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论