title: How to declare and use public functions and subroutines in Worksheet code
body: <p>I have a public function declared in one of my worksheet modules:</p>
  
  <pre><code>Public Function isValidContract(contract As String) As Boolean
      ' Code reads cell values from the worksheet and determines
      ' if passed-in contract is one of them.
  End Function
  </code></pre>
  
  <p>I'd like to be able to access it from other modules and Class modules. I've tried the following:</p>
  
  <pre><code>Public Sub someRandomSubInAntoherModule()
  
      Dim contract As String
      Dim sh as Worksheet
  
      ' Code that sets contract
      Set sh = Sheets("Matrix")
      If Not sh.isValidContract(contract) Then
          ' blah
      End If
  
  End Sub
  </code></pre>
  
  <p>But I get a compile error: "Method or data member not found", probably because I declared <code>sh</code> as a <strong>Worksheet</strong> object, and the <strong>Worksheet</strong> object doesn't have an <code>isValidContract()</code> method. But I want to use the <code>isValidContract()</code> method defined in my <em>Matrix</em> worksheet.</p>
  
  <p>The only way I can get it to work is to declare <code>sh</code> as an <strong>Object</strong>. But then I don't get the nifty little code hints when I type</p>
  
  <pre><code>sh.
  </code></pre>
  
  <p>Is there any way to dimension <code>sh</code> such that I get the code hints for the Worksheet object <em>and</em> my specific <em>Matrix</em> code?</p>