VBA:如何通过函数更改另一个单元格的值? [英] VBA: How to change the value of another cell via a function?

查看:709
本文介绍了VBA:如何通过函数更改另一个单元格的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Excel VBA新手。

I'm an Excel VBA newbie.

如何通过用户定义的函数更改指定单元格的值?这个代码有什么问题:

How to change the value of the specified cell via a user-defined function? What's wrong with this code:

Function Test(ByVal ACell As Range) As String
  ACell.Value = "This text is set by a function"
  Test := "Result"
End Function

我的愿望是...当我在单元格E1中输入 = Test(E6)时,Excel将在E6中显示指定的文本。

My wish is ... when I type =Test(E6) in cell E1, Excel will display the specified text in E6.

推荐答案

Excel VBA不允许用户定义的函数更改另一个单元格的值。
UDF允许做的唯一的事情(有一些小的例外)是将值从返回的单元格返回。

Excel VBA will not allow a user-defined function to alter the value of another cell. The only thing a UDF is allowed to do (with a few minor exceptions) is to return values to the cells it is called from.

这篇关于VBA:如何通过函数更改另一个单元格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆