title: Create a custom worksheet function in Excel VBA
body: <p>I have a faint memory of being able to use VBA functions to calculate values in Excel, like this (as the cell formula):</p>
  
  <pre><code>=MyCustomFunction(A3)
  </code></pre>
  
  <p>Can this be done?</p>
  
  <p>EDIT:</p>
  
  <p>This is my VBA function signature:</p>
  
  <pre><code>Public Function MyCustomFunction(str As String) As String
  </code></pre>
  
  <p>The function sits in the <code>ThisWorkbook</code> module. If I try to use it in the worksheet as shown above, I get the <code>#NAME?</code> error.</p>
  
  <hr>
  
  <p>Solution (Thanks, codeape): The function is not accessible when it is defined <code>ThisWorkbook</code> module. It must be in a "proper" module, one that has been added manually to the workbook.</p>