title: Compile error: method or data member not found when trying to run a code from a top StackOverflow answer
body: <p>This is my first experience with VBA. I wanted to use regular expression in Excel and found the following StackOverflow question. </p>
  
  <p><a href="https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops">How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops</a></p>
  
  <p>I added "Microsoft VBScript Regular Expressions 5.5" to my references in the VBA interface, and typed in <code>12abc</code> in cell <code>A1</code> as in the exmple. I then did Insert -> Module and copied the following code to the code box:</p>
  
  <pre><code>Function simpleCellRegex(Myrange As Range) As String
      Dim regEx As New RegExp
      Dim strPattern As String
      Dim strInput As String
      Dim strReplace As String
      Dim strOutput As String
  
  
  strPattern = "^[0-9]{1,3}"
  
  If strPattern &lt;&gt; "" Then
      strInput = Myrange.Value
      strReplace = ""
  
      With regEx
          .Global = True
          .MultiLine = True
          .IgnoreCase = False
          .Pattern = strPattern
      End With
  
      If regEx.test(strInput) Then
          simpleCellRegex = regEx.Replace(strInput, strReplace)
      Else
          simpleCellRegex = "Not matched"
      End If
  End If
  End Function
  </code></pre>
  
  <p>However, when I type in <code>=simpleCellRegex(A1)</code> in cell <code>B1</code> I get the error </p>
  
  <pre><code>Compile error: method or data member not found
  </code></pre>
  
  <p>And in the debugger mode the first line of the code is highlighted.</p>
  
  <p>Someone in the comments to the answer mentioned that an error might occur if the code is in <code>ThisWorkbook</code>, but mine in is <code>Modules</code>.</p>