title: How to call a user defined function in vba code
body: <p>I created a Public function in Module two called <code>"t_value"</code>. I now want to use this function in the VBA code for a userform, which uses the input from the userform.</p>
  
  <p>This is the function:</p>
  
  <pre><code>Public Function t_value(theta As Variant)
      Dim theta_1 As Integer, theta_2 As Integer
      Dim A As Variant, B As Variant, s As Variant
  
      theta_1 = Application.WorksheetFunction.Floor(theta, 5)
      theta_2 = Application.WorksheetFunction.Ceiling(theta, 5)
      A = theta - theta_1
      B = theta_2 - theta_1
      s = A / B
      t_value = s
  
  End Function
  </code></pre>
  
  <p>Here is the code I would like to use the function above in:</p>
  
  <pre><code>Private Sub Submit_Click()
      Dim theta As Variant, alpha As Variant, t As Variant, u As Variant
  
      theta = UserForm1.theta_input.Value
      alpha = UserForm1.alpha_input.Value
      t = Application.WorksheetFunction.t_value(theta)
  
  End Sub
  </code></pre>
  
  <p>Normally <code>"Application.WorksheetFunction.[function]"</code> works, but it wouldn't work for me in this situation - I thought it may be due to the fact I created the formula. Would it be easier to just put the formula into the Sub? I was worried about runtime. I'm rather new, so I'm not completely familiar with VBA syntax.</p>