非常感谢您协助我将自定义VBA函数中的数据写入Excel工作表。我已经能够从自定义VBA子例程写入,但在执行VBA函数时出错。在示例代码中,“Sub write 2”和“Sub write 3”工作正常。但是“功能测试2()”会产生“价值!”在其单元格中,write3不会被执行。
Sub write2(r As Integer, c As Integer, d As Double)
Dim a, b As Integer
For a = r To r + 1
For b = c To c + 1
Cells(a, b).Value = d
Next b
Next a
End Sub
Sub write3()
Call write2(3, 60, 0.437)
End Sub
Function test2() As Double
Call write3
test2 = 1#
End Function
答案 0 :(得分:3)
根据Chip Pearson's great website:
UDF只能向调用它的单元格返回一个值 - 它不能修改任何单元格的内容或格式,也不能修改Excel的操作环境。如果您尝试更改任何内容,该函数将立即终止并向调用单元格返回#VALUE错误。