title: How do I pass a variable from one function to another function?
body: <p>I am trying to pass a variable from one function to another function. </p>
  
  <p>My first thought is to use the ByRef declaration which I hear will pass arguments by reference in Visual Basic. I am unclear, however, on how to use it. Right now I have the following code.</p>
  
  <pre><code>            Function number(x As Double) As Double
  
                  Dim z As Double
                  z = 10.5
                  number = x
  
              End Function
  
              Function triple(ByRef z As Double) As Double
  
                  z = z * 3
                  triple = z
  
              End Function
  </code></pre>
  
  <p>Lets say <code>A1=2.5</code>. If I say <code>B1=number(A1)</code> then the answer is 2.5 which I expected it to be. I then say <code>B2=triple(B1)</code> but then the answer is 7.5 instead of 31.5. I am not sure why it's taking the value of <code>A1</code> instead of taking the value of the variable <code>z</code> from the function <code>number</code>.</p>
  
  <p>Here's a screenshot of the worksheet</p>
  
  <p><a href="https://i.stack.imgur.com/2qglQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2qglQ.png" alt="enter image description here"></a></p>
  
  <p>Thanks in advance.</p>