gpt4 book ai didi

vba - 如何将函数的结果返回到 Excel 中的单元格?

转载 作者:行者123 更新时间:2023-12-02 14:17:43 26 4
gpt4 key购买 nike

假设我的一张 Excel 工作表附加了一个函数:

Public Function foo(bar As Integer) as integer
foo = 42
End Function

如何将 foo 的结果返回到工作表上的单元格?我尝试过 "=foo(10)",但它给我的只是 "#NAME?"

我还尝试过 =[filename]!foo(10) 和 [sheetname]!foo(10) 没有任何变化。

最佳答案

尝试按照指示 here 进行操作确保你做的每件事都是正确的,特别是关于把它放在哪里。 (插入->模块)

我可以确认使用 Insert->Module 打开 VBA 编辑器以及以下代码:

Function TimesTwo(Value As Integer)
TimesTwo = Value * 2
End Function

在工作表上将 "=TimesTwo(100)" 放入单元格中,得到 200

关于vba - 如何将函数的结果返回到 Excel 中的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/558860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com