Reputation: 43
I want to get the value for function of test1 and test2, but when I call them in Excel it give value of 0
I already gave number value = 5
These are the codes:
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
Upvotes: 0
Views: 81
Reputation: 10139
Unless you are going to call your Subroutine input_variable
, your value Number
will not be set. If you do not intend on calling this Sub, then you need to convert it to a 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
Upvotes: 0
Reputation: 444
test1/2 can't understand what Number is, as Number is out of scope. you shoul include the Number in functions as below
Function test1()
Number = Range("number")
test1 = Number * Number
End Function
Function test2()
Number = Range("number")
test2 = Number * Number * Number
End Function
Upvotes: 2