我想得到test1和test2函数的值,但是当我在Excel中调用它时它给出的值为0
我已经给出了数值= 5
这些是代码:
Option Explicit
Public number As Double
Public Sub input_variable()
number = 4.2
End Sub
Function Test1() As Double
Test1 = number * number
End Function
Function Test2() As Double
Test2 = number * number * number
End Function
答案 0 :(得分:2)
test1 / 2无法理解Number是什么,因为Number超出了范围。你应该在下面的函数中包含数字
Function test1()
Number = Range("number")
test1 = Number * Number
End Function
Function test2()
Number = Range("number")
test2 = Number * Number * Number
End Function
答案 1 :(得分:0)
除非您打算调用子例程input_variable
,否则您的值Number
将不会被设置。如果您不打算调用此Sub,则需要将其转换为Function
Option Explicit
Function Number() As Double
Number = 4.2
End Function
Function Test1() As Double
Test1 = Number * Number
End Function
Function Test2() As Double
Test2 = Number * Number * Number
End Function